psylosss psylosss - 2 months ago 6
PHP Question

How to check wheather field is 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) }}

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.

Comments