diff --git a/src/FormHandler.php b/src/FormHandler.php index 2be9c45..82bdf08 100644 --- a/src/FormHandler.php +++ b/src/FormHandler.php @@ -90,9 +90,10 @@ public function registerHandler(FormHandlerInterface $handler): void /** * @param string|FormHandlerInterface $class - * @param mixed[] $options + * @param array $options * * @return FormRequest + * @throws \Exception */ public function handle($class, array $options = []): FormRequest { @@ -113,11 +114,11 @@ public function handle($class, array $options = []): FormRequest $form->handleRequest($this->request); - if ($handler instanceof FormHandlerResponseInterface) { - $formRequest->setResponse($handler->getResponse($formRequest)); - } - if (!$form->isSubmitted()) { + if ($handler instanceof FormHandlerResponseInterface) { + $formRequest->setResponse($handler->getResponse($formRequest)); + } + return $formRequest; } @@ -131,6 +132,8 @@ public function handle($class, array $options = []): FormRequest if ($response = $event->getResponse()) { $formRequest->setResponse($response); + } else if ($handler instanceof FormHandlerResponseInterface) { + $formRequest->setResponse($handler->getResponse($formRequest)); } return $formRequest;