Uh oh!
There was an error while loading.Please reload this page.
- Notifications
You must be signed in to change notification settings - Fork9.6k
Closed
Labels
Description
I'm calling out for you to decide how to resolve the inconsistency between theForm::isValid()
method and thevalid
variable available in the template:
isValid()
returnsfalse
if a form was not submitted. This way it is possible to write concise controller code:
$form =$this->createForm(...);$form->handleRequest($request);if ($form->isValid()) {// only executed if the form is submitted AND valid}
valid
containstrue
if a form was not submitted. This way it is possible to rely on this variable for error styling of a form.
<div{%ifnotform.vars.valid %}class="error"{%endif %}>
We have two alternatives for resolving this problem:
- Leave the inconsistency as is.
- Make
isValid()
returntrue
if a form was not submitted (consistent withvalid
) - Revert to the 2.2 behavior of throwing an exception if
isValid()
is called on a non-submitted form (not consistent withvalid
).
Both 2. and 3. will require additional code in the controller:
$form =$this->createForm(...);$form->handleRequest($request);if ($form->isSubmitted() &&$form->isValid()) {// only executed if the form is submitted AND valid}
What do you think?