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

為{幸葍}努か 提交于 2019-12-03 04:18:45

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 :)
));

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))
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!