Symfony Custom Field 2

Asked

Viewed 50 times

0

How to write a custom form field on Symfony2? Since in this form should appear:

  • A field of type Dropdown with the label City;
  • Another field of the kind number alongside the label door number.

1 answer

0

You have two options:

1 - Manually place the fields inside the form and pick up the wall meters via $request inside the controller.

HTML

{{ form_start(form) }}
  <select name='cidades'>
    <option value="">Selecione a Cidade</option>
    {% for cidade in cidades %}
      <option value="{{cidade.id}}">{{cidade.nome}}</option>
    {% endfor %}
    </select>
{{ form_end(form) }}

Controller:

$request->request->get('cidades');

2 - Use Symfony default mode and work Form with Arraycollection.

Embed Collection of Forms

Browser other questions tagged

You are not signed in. Login or sign up in order to post.