Looking for more information on how to do PHP the right way? Check out PHP: The Right Way

Eric Barnes:
How To: Validate an array of form fields with Laravel
Apr 07, 2015 @ 14:48:34

Eric Barnes has a new post to his site showing you how to validate form input in a Laravel application using the form requests feature.

If you’ve used Laravel’s form validation for any length of time, then you know it’s a powerful system. It makes the tedious task of validation very simple while still keeping the door open for complex rules. In this tutorial, I want to show you a simple and easy way of validating forms that contain dynamic fields. A common use case for these types of forms is when you would like to allow a user to add more fields to a form.

His example uses a form with a handful of text fields rendered with a simple "for" loop in the template. He then helps you make a new Request instance (OrderRequest) and adding custom validation rules into its "rules" method. In this case, he sets a rule that the content is required and can be no longer than 255 characters. He also shows how to use the custom messages functionality, defining custom values for each of the form's fields.

tagged: validate form data laravel formrequests example tutorial

Link: http://ericlbarnes.com/laravel-array-validation/


Trending Topics: