Join GitHub today
GitHub is home to over 36 million developers working together to host and review code, manage projects, and build software together.Sign up
[Form] Show errors even without submit #32336
I have quite a few forms where the data in the form is highly "changeable" over time, which usually means that a previously valid value is not valid anymore (for example a product in the cart was available before, but now it is not available anymore). Currently, a form only shows its errors when it is submitted, but often this is not very user-friendly: if you can point out what needs to be adjusted in existing data right when somebody opens the form then the user knows right away what needs to change, and this kind of form validation would be the same whether the form was just opened or submitted.
My suggestion would therefore be:
This gives a developer more flexibility, as a form can point out some errors right when the form loads if, for example, it has existing data which can be checked and has to be changed. These changes would also be backwards-compatible, especially if the showing form errors without submission is opt-in.
I would be ready to help implement this kind of functionality, but first wanted to find out if a change like this would be welcome or not, or what the thoughts are behind the current behavior versus this proposed change.
A slight amendment: With these changes it might make sense to also have an additional event after PRE_SUBMIT that is always run (so even without form submission the form could be changed / parts added or removed) in addition to the event after POST_SUBMIT that is always run.
That way a form can dynamically change according to the current form data (with submitted data taken into account if the form was submitted, or using preexisting data if not), so parts could be added or removed after PRE_SUBMIT, and additional always-run validation would be possible after POST_SUBMIT. In terms of how they work they could be named PRE_SUBMIT_ALWAYS and POST_SUBMIT_ALWAYS, although one might find better names for it.
I can give additional use cases about the advantages of these features if it remains unclear, or go more into specifics.
An explicit call to $form->submit as a "workaround" has the following drawbacks:
Two common use cases for my suggestions: