Symfony Forms


When the LeviyUserInterfaceBundle is enabled, it is possible to use forms created with the Symfony Form component. Floating labels, custom checkboxes and radio buttons will automatically be enabled.

Buttons should be added to the templates, and not to the form classes. So to render a form with buttons, use the following code in your Twig template:

Some help text.
Checkboxes
Radio buttons
Cancel
{% import '@leviy-templates/macros/buttons.html.twig' as buttons %}

{{ form_start(form) }}
{{ form_widget(form) }}

{{ buttons.link('Cancel', '', '#') }}
{{ buttons.button('Save', 'primary', 'submit') }}
{{ form_end(form) }}

Validation

When a submitted form contains validation errors, the input elements are marked as invalid and error messages are shown under them:

Please enter your email address
Checkboxes
Please select at least one option
Please select at least one option
Please select at least one option

Form errors

There can also be errors with the submitted form as a whole, instead of with individual input elements:

The CSRF token is invalid. Please try to resubmit the form.
Checkboxes

Forms within a Alert Dialog

You can also put a form inside an Alert Dialog. If you want, you can also add a delay to the submit button. For example, a delete form that deletes important data, can have a delay of 2000ms to the submit button for extra safety.

{{ form_start(form, {'attr': {
    'data-alert-dialog-title': 'Delete all files from this user?',
    'data-alert-dialog-body': 'This will permanently delete these files from Leviy. Warning: this cannot be undone!',
    'data-alert-dialog-dismiss': 'Cancel',
    'data-alert-dialog-confirm': 'Delete all',
    'data-alert-dialog-confirmation-delay': true
}}) }}

{{ buttons.button('Open Modal', 'primary', 'submit') }}

{{ form_end(form) }}