-
-
Notifications
You must be signed in to change notification settings - Fork 37
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
Add input filter validation to fieldset tutorial #68
Comments
Thanks for the report @Redcentaur - you are welcome to send a patch to improve the docs if you are able… It could be a case of adding links to other existing docs in the pertinent places. |
@gsteel I'd love to be in a position to help and perhaps one day soon I will be able to, but I don't think I know enough about Laminas at this stage to add to the tutorial competently (which is why I'm doing the tutorial :) ) |
👍 - Good luck with it, and don't forget the forum and slack if you run into any trouble :) |
Good point because the used form elements |
No they don't, but they can and should still have filters (StripTags/StringTrim) and validators (StringLength) etc relevant to the expected input. What I'm not sure about is how to inject the inputFilter for the form, set the data on it, validate the data and retrieve the data from it in the Controller when the form has a fieldset. I get form validation errors saying the fields are required and cannot be empty, when they have been populated. |
Correct and I didn't want to doubt this, on the contrary, this part is missing in the tutorial. I will add this part.
There are some more tutorials: "Application Integrations" For example: |
Hi Frank I have done some research and got an InputFilter working with the tutorial code. I'm not sure if this is best practice or not? First, in the Post.php file, add the references, Interface implementation and create a parameter to hold the InputFilter:
Then create the InputFilter setter and getter methods at the end of the Post class:
Next, in the WriteController, we need to add the Post reference at the top of the file:
Then we need to alter the
Now we can set the form's InputFilter using the InputFilter get method from the Post entity. Because we used a Fieldset in our form, we need to set a validation group on the form, so that the InputFilter is applied to the correct fieldset:
The Finally, for
In the
Is this correct and does it make sense? |
Too complicated. 😜 Define the input filter in a form and you are done. Follow the description I have given you above: You will find the same procedure in the documentation of laminas-form: For further questions, please use our forum or the chat. |
In the in-depth tutorial you add the use of laminas-form and laminas-form-fieldset and in the Controller check for validity of the inputs. In the conclusion of that section, it is claimed that we've learnt how to validate input but we haven't: the input to the fields is not validated because we haven't created an input filter or attached any validators to the form or to the fieldset containing the form data.
I think it is particularly important to cover this topic as you are using fieldset in the form for the object hydrator and this can make setting data on the form and collecting data back from valid forms difficult with input filters. Can you cover it in more detail please?
The text was updated successfully, but these errors were encountered: