Skip to content

Commit 79e453f

Browse files
committed
Prevent unnecessary reponse rendering
1 parent d19ae55 commit 79e453f

File tree

1 file changed

+8
-5
lines changed

1 file changed

+8
-5
lines changed

src/FormHandler.php

Lines changed: 8 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -90,9 +90,10 @@ public function registerHandler(FormHandlerInterface $handler): void
9090

9191
/**
9292
* @param string|FormHandlerInterface $class
93-
* @param mixed[] $options
93+
* @param array<mixed> $options
9494
*
9595
* @return FormRequest
96+
* @throws \Exception
9697
*/
9798
public function handle($class, array $options = []): FormRequest
9899
{
@@ -113,11 +114,11 @@ public function handle($class, array $options = []): FormRequest
113114

114115
$form->handleRequest($this->request);
115116

116-
if ($handler instanceof FormHandlerResponseInterface) {
117-
$formRequest->setResponse($handler->getResponse($formRequest));
118-
}
119-
120117
if (!$form->isSubmitted()) {
118+
if ($handler instanceof FormHandlerResponseInterface) {
119+
$formRequest->setResponse($handler->getResponse($formRequest));
120+
}
121+
121122
return $formRequest;
122123
}
123124

@@ -131,6 +132,8 @@ public function handle($class, array $options = []): FormRequest
131132

132133
if ($response = $event->getResponse()) {
133134
$formRequest->setResponse($response);
135+
} else if ($handler instanceof FormHandlerResponseInterface) {
136+
$formRequest->setResponse($handler->getResponse($formRequest));
134137
}
135138

136139
return $formRequest;

0 commit comments

Comments
 (0)