macwinnie / twigbundle-form
A Twig Bundle providing some helper templating for forms
Installs: 18
Dependents: 0
Suggesters: 0
Security: 0
Stars: 0
Watchers: 2
Forks: 0
Open Issues: 0
Type:twig-bundle
Requires
This package is auto-updated.
Last update: 2025-05-01 00:14:18 UTC
README
This Twig Bundle allows to reuse some helpful Form elements ... as Twig Macros.
WARNING: as always when working with forms ... the view isn't the (only) place to verify if a user is allowed to send specific information ... if you disable a form element or make it read only in the view, you also want to prove the data sent does not contain that specific value changed!
Data structures
As always, a template is using a dedicated data structure to be transferred into a view ... So the following section is on how the data has to be structured for the usage of the provided macros:
Form
The form
macro is using a Bootstrap-DIV-based layout and can be adapted easily. To use it, you'll want to require the \macwinnie\TwigbundleForm\FormExtension
class as Twig extension:
Form Element
By default, if none of the following options is selected, we'll get a <input>
field rendered by this macro. If
Example usage
This is an example of a Twig template on how to build forms and a single form element:
<h3>Form-Testing</h3> {% set form_data = { "create": { "action": "/tests/helper/?" }, "buttons": [ { "text": "submit", "class": "btn btn-primary", "name": "submitbutton", "value": "submit_val" } ], "rows": [ { "name": "text", "placeholder": "ph text", "type": "text", "title": "single line textfield" } ] } %} {% import "form.twig" as forms %} {% import "formelement.twig" as formelement %} {{ forms.create( form_data ) }} <hr/> {{ formelement.create( form_data.rows[0] ) }}