Symfony Custom Field 2

0

How to write a custom form field in Symfony2 ? In this form you should see:

  • A Dropdown field with the label City;
  • Another field of type number next to the label port number.
asked by anonymous 13.08.2016 / 17:33

1 answer

0

You have two options:

1 - Place the fields manually inside the form and pick up the parameters 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 standard mode and work the Form with ArrayCollection.

Embed Collection of Forms

    
08.05.2017 / 18:37