Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

symfony2 textfield custom label

I had a little but unpleasant problem with symfony2 Field component. For example, I would like to output array of form fields in twig template:

{% for field in form %}
    {{ form_label( field ) }}: {{ form_field( field ) }}
{% endfor %}

And here is text field configuration:

$field = new TextField( 'FieldName', array(
    'label' => 'MyCustomLabel',
) );

But unfortunately when engine renders this output i get 'FieldName' as label instead of 'MyCustomLabel'. I would not have problems if i outputting form fields not in for (in that case i can just add a label in template for each field). But the script doesn't know certain quantity and configuration of form fields before execution. So, I need to implement cycle method for field rendering. And I also want to stay in twig notation...I will be pleased for a good advise :)

like image 734
Aleksei Kornushkin Avatar asked Apr 05 '11 11:04

Aleksei Kornushkin


1 Answers

If you want to change the label, than follow the steps. 1) Create form class. 2) add('fieldName',null,array('label' => 'My New Label:'))

please do not change fieldName, but you can play with Label within an array.

Enjoy!

like image 121
Rikin Adhyapak Avatar answered Sep 22 '22 06:09

Rikin Adhyapak