diff --git a/src/Forms/FormRequestHandler.php b/src/Forms/FormRequestHandler.php index 67e0d755b2f..bc2ca143786 100644 --- a/src/Forms/FormRequestHandler.php +++ b/src/Forms/FormRequestHandler.php @@ -236,6 +236,11 @@ public function httpSubmission($request) return $this->$funcName($vars, $this->form, $request); } + // Otherwise, try a handler method on the form itself + if ($this->form->hasMethod($funcName)) { + return $this->form->$funcName($vars, $this->form, $request); + } + // Check for inline actions $field = $this->checkFieldsForAction($this->form->Fields(), $funcName); if ($field) { diff --git a/tests/php/Forms/FormRequestHandlerTest.php b/tests/php/Forms/FormRequestHandlerTest.php new file mode 100644 index 00000000000..2206c856d4c --- /dev/null +++ b/tests/php/Forms/FormRequestHandlerTest.php @@ -0,0 +1,45 @@ +disableSecurityToken(); + $handler = new TestFormRequestHandler($form); + $request = new HTTPRequest('POST', '/', null, ['action_mySubmitOnFormHandler' => 1]); + $response = $handler->httpSubmission($request); + $this->assertFalse($response->isError()); + } + + public function testCallsActionOnForm() + { + $form = new TestForm( + new Controller(), + 'Form', + new FieldList(), + new FieldList(new FormAction('mySubmitOnForm')) + ); + $form->disableSecurityToken(); + $handler = new FormRequestHandler($form); + $request = new HTTPRequest('POST', '/', null, ['action_mySubmitOnForm' => 1]); + $response = $handler->httpSubmission($request); + $this->assertFalse($response->isError()); + } +} diff --git a/tests/php/Forms/FormRequestHandlerTest/FormRequestHandler.php b/tests/php/Forms/FormRequestHandlerTest/FormRequestHandler.php new file mode 100644 index 00000000000..6de7ffe2b65 --- /dev/null +++ b/tests/php/Forms/FormRequestHandlerTest/FormRequestHandler.php @@ -0,0 +1,14 @@ +