-
-
Notifications
You must be signed in to change notification settings - Fork 9.6k
[Form] Form::getErrors() method is confusing for new symfony users #25738
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
Comments
Could we to deprecate the |
@yceruto You mean as first step deprecating |
Yes, exactly, with |
IHMO the actual behaviour of The real problem of beginners is that they don't understaind that a form is a tree of fields and not a flat array of fields. Maybe it is a good moment for them to realize that fact when they face the result of |
Default |
This was "true" before, but now the debug bar contains a form and a constraints panel. Beginners should learn to use the debug bar. The doc is also OK: https://symfony.com/doc/current/components/form.html#accessing-form-errors |
Finding errors via profiler bundle is a workaround. It doesn't change the fact current behaviour of that method is confusing. Also, people use Form component outside of symfony framework too. |
Just my $0.02 here: I'd suggest changing the name of the method from The name change would work well with the deprecation and switch of the default values as well. |
I very much like the original proposal - something like getAllErrors() and getOwnErrors(). Someone should make a PR :). |
I've provided a PR. As stated there this will be a BC break after all. |
There are 2 competing PRs now, we should close one :) I like to suggest current
|
@ro0NL The whole point of this issue is the fact that it does NOT convey that meaning at all. Read the initial post. I do agree that |
I did :) and i think providing 2 methods starting with I think assuming isValid=false meaning getErrors will not be empty is another perspective. |
...Removed... Updated on 2019-05-05: In controller:
|
Why would the form be invalid with that logic? Validation is the current state + sum of the children's state. Why would errors be any different? "getErrors()" is the explanation to the validity state. IMO this method started out as a bug. @yarcowang If that works that would be AMAZ-sauce. |
Thank you for this suggestion. |
yes |
Thank you for this suggestion. |
Yes |
Is someone up for a PR? The bot is a sign that progress on this issue has stalled, which is never a good sign for a feature request |
I am going to close here as we never managed to agree on any better solution. |
Several times now I saw new inexperienced symfony users getting confused by the
Form::getErrors()
method. The problem is the boolean$deep
parameter with afalse
default value. Usually it goes like this:$form->isValid()
returns false. Wait what's wrong?$form->getErrors()
to see the problem!And here they get stuck for half an hour or more. Of course there is an error but you'll only see it with
$form->getErrors(true)
. I confess that this took me a while to figure out as well when I was new to Symfony. Boolean parameters are just evil.To remove this confusion I suggest to deprecate the
getErrors
method in favor of two new methodsgetAllErrors
andgetOwnErrors
. I can send a PR if this change is wanted.The text was updated successfully, but these errors were encountered: