Symfony 2 : Add a custom form element, not in an Entity Symfony 2 : Add a custom form element, not in an Entity symfony symfony

Symfony 2 : Add a custom form element, not in an Entity


An update for Symfony 2.1:

property_path has been deprecated and instead you should use mapped. The syntax remains the same:

->add('password_confirmation', 'password', array('mapped' => false))


In a normal situation, you'd need to explicitly specify that *password_confirmation* isn't part of the entity, using the property_path option.

->add('password_confirmation', 'password', array('property_path' => false))

And then to validate it with a CallBackValidator.

But, in this specific case, where you want to repeat a field, the repeated widget can do that for you.

->add('password_confirmation', 'repeated', array(    // See the docs :)));