-
-
Notifications
You must be signed in to change notification settings - Fork 9.6k
[Form] Add a form error if post_max_size has been reached. #11877
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -12,6 +12,8 @@ | |
namespace Symfony\Component\Form\Extension\HttpFoundation; | ||
|
||
use Symfony\Component\Form\Exception\UnexpectedTypeException; | ||
use Symfony\Component\Form\Extension\Validator\Util\ServerParams; | ||
use Symfony\Component\Form\FormError; | ||
use Symfony\Component\Form\FormInterface; | ||
use Symfony\Component\Form\RequestHandlerInterface; | ||
use Symfony\Component\HttpFoundation\Request; | ||
|
@@ -24,6 +26,19 @@ | |
*/ | ||
class HttpFoundationRequestHandler implements RequestHandlerInterface | ||
{ | ||
/** | ||
* @var ServerParams | ||
*/ | ||
private $serverParams; | ||
|
||
/** | ||
* {@inheritdoc} | ||
*/ | ||
public function __construct(ServerParams $params = null) | ||
{ | ||
$this->serverParams = $params ?: new ServerParams(); | ||
} | ||
|
||
/** | ||
* {@inheritdoc} | ||
*/ | ||
|
@@ -61,6 +76,10 @@ public function handleRequest(FormInterface $form, $request = null) | |
$params = $request->request->get($name, $default); | ||
$files = $request->files->get($name, $default); | ||
} else { | ||
if ($this->serverParams->getContentLength() > $this->serverParams->getPostMaxSize()) { | ||
$form->addError(new FormError('Max post size exceeded.')); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Please also add this string in the There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. the form needs to be marked as submitted in this case though, so that the code can know that a submission ended up with errors rather than thinking it is not submitted (and so it is the initial display) There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. @stof thank for your feedback, i'm agree with you but i don't know how to tackle this : if i simply set $submitted to true the web profiler don't see the form as submitted but if i submit the form, $errors is cleared. |
||
} | ||
|
||
// Don't submit the form if it is not present in the request | ||
return; | ||
} | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
this should get the values from the Request object instead of using ServerParams
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
forget it, the ServerParams takes care of it