-
-
Notifications
You must be signed in to change notification settings - Fork 9.6k
Deprecate using Form::isValid() with an unsubmitted form #17644
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
Conversation
50365e3
to
ce83739
Compare
We cannot do 2. as it would be a BC break (and would be impossible to make it a soft-migration as there would be no sane way to decide what we should return in this method: the old or new return value) |
ce83739
to
c7494e3
Compare
👍 |
ping @symfony/deciders |
@Ener-Getick Can you fix the tests? |
Also, can you update the CHANGELOG/UPGRADE files? |
@fabpot i won't be able to do it during the next weeks but of course i'll do it as soon as i can ☺ |
@@ -724,6 +724,8 @@ public function isEmpty() | |||
public function isValid() | |||
{ | |||
if (!$this->submitted) { | |||
@trigger_error('Call Form::isValid() with an unsubmited form is deprecated since version 3.1 and will throw an exception in 4.0. Use Form::isSubmitted() before Form::isValid() instead', E_USER_DEPRECATED); |
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.
... since 3.2 ...
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.
indeed, thanks !
5a639dd
to
7c3164f
Compare
After all I found some time to update this PR. |
Looks good Status: reviewed (oh, btw, the color of "feature" and "status: reviewed" labels look very ugly next to eachother) |
Thank you @Ener-Getick. |
…rm (Ener-Getick) This PR was merged into the 3.2-dev branch. Discussion ---------- Deprecate using Form::isValid() with an unsubmitted form | Q | A | ------------- | --- | Bug fix? | no | New feature? | yes | BC breaks? | no | Deprecations? | yes | Tests pass? | yes | Fixed tickets | #7737 | License | MIT | Doc PR | not yet > I'm calling out for you to decide how to resolve the inconsistency between the Form::isValid() method and the ``valid`` variable available in the template: > > - ``isValid()`` returns ``false`` if a form was not submitted. This way it is possible to write concise controller code: > > ```php > $form = $this->createForm(...); > $form->handleRequest($request); > if ($form->isValid()) { > // only executed if the form is submitted AND valid > } > ``` > > - ``valid`` contains ``true`` if a form was not submitted. This way it is possible to rely on this variable for error styling of a form. > > ```twig > <div{% if not form.vars.valid %} class="error"{% endif %}> > ``` > > We have two alternatives for resolving this problem: > > 1. Leave the inconsistency as is. > 2. Make ``isValid()`` return ``true`` if a form was not submitted (consistent with ``valid``) > 3. Revert to the 2.2 behavior of throwing an exception if ``isValid()`` is called on a non-submitted form (not consistent with ``valid``). > > Both 2. and 3. will require additional code in the controller: > > ```php > $form = $this->createForm(...); > $form->handleRequest($request); > if ($form->isSubmitted() && $form->isValid()) { > // only executed if the form is submitted AND valid > } > ``` > > What do you think? This PR implements the option 3 as it was the most chosen in #7737 Commits ------- 2c3a7cc Deprecate using Form::isValid() with an unsubmitted form
Hello. I know it's a bit late for this one, But I would like to vote for the 2/ options. Or We could implement something different: changing the value of |
@lyrixx I would create a PR or an issue instead of commenting on an already merged PR. |
@lyrixx Though note that option 2 would be a BC break as pointed out by @stof (see #17644 (comment)). |
This PR implements the option 3 as it was the most chosen in #7737