All TextTypes are NULL Symfony 3

41 views Asked by At

Why I get null in all the fields of my form?

form

The buildForm is this:

  ->add('name', TextType::class, array(
       'label' => 'Nombre',
       'required' => 'required',
//     'empty_data' => null,
       'empty_data' => '',
       'attr' => array(
           'class' => 'form-name form-control'
        )
        ))
        ->add('surname', TextType::class, array(
             'label' => 'Apellidos',
             'required' => 'required',
             'attr' => array(
                 'class' => 'form-surname form-control'
              )
       ))

The result is the same. I tried with and without empty_data. How do I delete this null?

I am new in Symfony, I start learning.

Thanks for your patience.

1

There are 1 answers

3
Youssef Saoubou On

Use placeholder:

           ->add('name', TextType::class, array(
                'label' => 'Nombre',
                'required' => 'required',
                'attr' => array(
                    'class' => 'form-name form-control',
                    'placeholder' => 'place your name',
                )
            ))