Laravel Form Builder – Quickly and Easily Build Flexible Forms
For such a project, you might decide to create a “classic” Laravel application. And that would be a great decision because Laravel is perfect for that type of work! The same application will both process the form requests and render the forms.
But look at the “simple” form again and imagine how many manual tasks you may need to perform to create a form like that. And what if you have a few similar forms that are implementing the CRUD? Are you going to create reusable templates or something?
The Form Builder package enables you to avoid all the tedious manual work and cast aside any concerns about reusing the code.
You can use the Form Builder to quickly and easily perform the following functions:
- Create labels
- Find any validation errors in your templates
- Use Bootstrap CSS classes and layouts
- Bind a certain route and model entity to your form
- And much, much more!
At the same time, you aren’t restricted by the default appearance or behavior of this package. You can customize any piece of your project so that it is unique to your needs. You can change just one form or can update multiple forms that are stored in a single place if you wish to apply a modification across an entire project.
So, how does it work?
You may remember “FormHelper” for CakePHP (if you are old enough, ha, ha). It solved the same problem and did it well enough. The Laravel Form Builder package does similar things, but with a more accessible and modern approach that uses all the Laravel features that we have become accustomed to:
It looks intuitive, and in this case:
- The form will be submitted to the route bound with the “update” method of the Article Controller.
- The input values will be prefilled by fields from the provided $article entity.
- The form will have input for the article field “name” and also a label near it.
- The field will show validation errors near related fields in case it is not validated.
- The form contains hidden fields for CSRF tokens and the method name (for example, PUT) of the route.
As such, it generates the following HTML code:
Of course, you can change the Bootstrap Grid, remove it, arrange the labels in a separate column, refrain from using Bootstrap at all, or even override the package templates…
All of this can be adjusted via config globally or for a single form. You can find the full list of abilities documented in our GitHub repository:
The best news of all? All the features are covered by unit tests!