Skip to content

Instantly share code, notes, and snippets.

@Remiii
Last active August 29, 2015 14:17
Show Gist options
  • Select an option

  • Save Remiii/6d87641528d068929e8b to your computer and use it in GitHub Desktop.

Select an option

Save Remiii/6d87641528d068929e8b to your computer and use it in GitHub Desktop.
PIMP Symfony Form with Twig

PIMP Smyfony Form with Twig

Because PIMP templating sucks in FormType 😱

// ...
{{ form_start(form, {'attr': {'class': '','data-parsley-validate':'', 'id' : 'request-form'}}) }}
<div class="form-group form-group-lg">
{{ form_label(form.name, 'your_name'|trans|capitalize) }}
{{ form_errors(form.name) }}
{{ form_widget(form.name, {'attr': { 'data-parsley-trigger':'change', 'data-parsley-minlength':'5', 'placeholder': 'Ex: Tom'}}) }}
</div>
<div class="form-group form-group-lg">
{{ form_label(form.email, 'your_email'|trans|capitalize) }}
{{ form_errors(form.email) }}
{{ form_widget(form.email, {'attr': { 'data-parsley-trigger':'change', 'data-parsley-type':'email', 'placeholder': 'Ex: tom@gmail.com'}}) }}
</div>
<div class="form-group form-group-lg">
{{ form_label(form.phone, 'your_phone_number'|trans|capitalize) }}
{{ form_errors(form.phone) }}
{{ form_widget(form.phone, {'attr': { 'data-parsley-trigger':'change', 'data-parsley-minlength':'10', 'placeholder': 'Ex: 01 67 19 34 87'}, 'label_attr': {'class': 'col-sm-12'}}) }}
</div>
<div class="form-group form-group-lg">
{{ form_label(form.address, 'your_address'|trans|capitalize) }}
{{ form_errors(form.address) }}
{{ form_widget(form.address, {'attr': { 'placeholder': 'Ex: 1 rue des pommes, 75001 Paris'}, 'label_attr': {'class': 'col-sm-12'}}) }}
</div>
<div class="checkbox">
{{ form_errors(form.optin) }}
{{ form_widget(form.optin, {'label': 'text_optin'|trans|nl2br}) }}
</div>
{{ form_row(form.ok, {'label': 'validate'|trans|capitalize, 'attr': { 'class': 'btn btn-success btn-lg' }}) }}
{{ form_end(form) }}
// ...
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment