0

I want to customize my form submit button label from "submit" to "Edit" in some of pages , and "submit" to "Add" in some other pages, with twig and Symfony 3.4 as this :

{{ form(form) }}
{{ form_widget(form.submit,{'label':'edit'}) }}

but this is not working for me :/ I see the documentation about all of that in the Symfony offcial website, but this didn't help me .

So can any one help me please?

thank you

sohaieb azaiez
  • 768
  • 9
  • 20

2 Answers2

1

Instead of form_widget, try form_row

{{ form_row(form.submit, { 'label': 'edit' }) }}
Pankaj
  • 571
  • 5
  • 20
  • Thank you it works good , just I have a last quetion : how can I add this form_row as a single customized row and display others in a signle line (without writing all rows) thank you in advance – sohaieb azaiez Mar 20 '18 at 21:50
  • like this :
    {{ form_row(form.Name) }}
    is that what you want ?
    – Pankaj Mar 21 '18 at 10:07
  • or you want to add custom parameters like class or any other data paramters to that form element ? – Pankaj Mar 21 '18 at 10:08
  • Not this, I mean , I want for example to write : {{ form(all 1st_parts_of_all_forms_elements) }} then finally {{ form_row(form.submit, { 'label': 'edit' }) }} to prevent writing all form rows .. I mean to prevent writing like this : {{ form_row(form.Name) }} {{ form_row(form.LastName) }} {{ form_row(form.Age) }} .. {{ form_row(form.submit, { 'label': 'edit' }) }} did you understand what I mean please ? – sohaieb azaiez Mar 21 '18 at 20:40
  • Ohh ok, now I got it so for that you can simply use for loop [https://twig.symfony.com/doc/2.x/tags/for.html] on form object. – Pankaj Mar 22 '18 at 11:18
  • I'm sorry but the page that you sent to me , is Not Found :( – sohaieb azaiez Mar 22 '18 at 21:02
  • Ohh Sorry, please check now : http://twig.symfony.com/doc/2.x/tags/for.html – Pankaj Mar 23 '18 at 09:09
  • Thank you , but I didn't find the right answer for my last question. – sohaieb azaiez Mar 23 '18 at 14:30
0

in form widget it is also is posible, you can also set class for bootstrap btn class for example

in FormType add

$builder
  ->add('save', SubmitType::class)

in TWIG

{{ form_widget(form.save, {'attr': {'class': 'btn btn-warning'},  'label': 'YourLabelName'  } ) }}
zoore
  • 293
  • 5
  • 13