Skip to content
Advertisement

How to check whether field exists in symfony2 form?

Using this manual, I added dynamic field to my form. Now, how can I check existence of this field in my template?

{{ form_start(form) }}
  {{ form_errors(form) }}

  {% if ??? %}     <---------------------------
    {{ form_row(form.myDynamicField) }}
  {% endif %}
{{ form_end(form) }}

Advertisement

Answer

What about,

{% if form.myDynamicField is defined %}
    {{ form_row(form.myDynamicField) }}
{% endif %}

You may also need to check if form.myDynamicField is not null.

User contributions licensed under: CC BY-SA
7 People found this is helpful
Advertisement