Symfony2: widget option does not exist

I am trying to create a form using symfony2, but I always get the error message "Widget" option "does not exist" when I add a widget parameter to indicate the type of form field.

I follow the example given in the documentation there http://symfony.com/doc/current/book/forms.html

here is my code that doesn't work.

class UserType extends AbstractType { public function buildForm(FormBuilder $builder, array $options) { $builder ->add('Name') ->add('Login') ->add('Password')//, 'text', array('widget' => 'password')) ->add('ConfirmPassword')//, 'text', array('widget' => 'password', 'label' =>'Confirm Password')) ->add('Email', 'text', array('widget' => 'email')) ->add('ConfirmEmail')//,'text', array('widget' => 'email', 'label' =>'Confirm Email')) //... } 

Does anyone know why? Thanks

+4
source share
1 answer

I believe that the right way to do what you want to achieve is as follows:

 ->add('Name', 'text') ->add('Login', 'text') ->add('Password', 'password') ->add('ConfirmPassword', 'password', array('label' =>'Confirm Password')) ->add('Email', 'email') ->add('ConfirmEmail', 'email') 

The first argument to the add method is the name field (it must be unique in the form). The second is type , and it is responsible for the form that the widget takes when rendering. The list of built-in types is here . The third argument is an array of parameters. Each type has its own set of possible options . Indeed, some types have a widget parameter. For example, date has this option. But password and email types do not have this capability.

+7
source

Source: https://habr.com/ru/post/1401956/


All Articles