I’m trying to build a form using symfony2, but I keep getting the error message ‘The option “widget” does not exist ‘ whenever I add the widget option to specify a form field type.
I’m following the example given on the documentation there http://symfony.com/doc/current/book/forms.html
here is my code that does not 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'))
//...
}
Anyone knows why ?
Thanks
I believe, the correct way to do what you want to achieve is the following:
The first argument of
addmethod is field’sname(it has to be unique within form). The second istypeand it is responsible for the form taken by widget while rendering. The list of built-in types here. The third argument is array of options. Eachtypehas it’s own set of possibleoptions. Indeed, some of types have thewidgetoption. For exampledatetype has such option. Butpasswordandemailtypes don’t have such option.