Issue
WAI validation requires label with for attribute associated with every form inputs.
How can I add label on form from this code?
public function buildForm(FormBuilderInterface $builder, array $options)
{
$builder
->add('nom', 'text', array(
'required' => false,
'attr' => array(
'placeholder' => 'Nom, Prénom', ),
))
;
}
Things like this do not work:
public function buildForm(FormBuilderInterface $builder, array $options)
{
$builder
->add('nom', 'text', array(
'label' => 'whatever',
'required' => false,
'attr' => array(
'placeholder' => 'Nom, Prénom', ),
))
;
}
Solution
You need to add {{ form_label(form.nom) }}
separately if you are not rendering the whole form.
Take a look here
Do something like this in your code:
{{ form_start(form, {'method': 'POST'}) }}
{{ form_label(form.nom) }}
{{ form_widget(form.nom) }}
{{ form_end(form) }}
and it should work.
Answered By - Dipen Shah Answer Checked By - Gilberto Lyons (PHPFixing Admin)
0 Comments:
Post a Comment
Note: Only a member of this blog may post a comment.