In my Symfony 4 form, I am try to get a placeholder for my input. I tried the below but I get an error that it is not allowed. Any ideas how else I can achieve this?
->add('firstname', TextType::class, ['label' => 'Vorname ', 'placeholder' => 'Your name',])
As suggested in the documentation I have also tried the below, here I am not getting an error, just nothing is rendering.
->add('firstname', TextType::class, ['label' => 'Vorname '], ['attr' => ['placeholder' => 'Vorname ']])
You need to do like this :
->add('firstname', TextType::class, array(
'label' => 'Vorname ',
'attr' => array(
'placeholder' => 'hereYourPlaceHolder'
)
))
As they say in the documentation
This also works, by rendering the items individually and adding an attribute in the twig!
{{ form_label(form.firstname) }}
{{ form_widget(form.firstname, {'attr': {'placeholder': 'FIRSTNAME'}}) }}
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With