如何避免多次存储 Symfony 表单的重复字段?
我正在使用 Symfony 1.4 和 Doctrine。我有一个型号 A,带有电子邮件字段。 A 的形式显示一个输入,用户应在其中正确插入电子邮件。但众所周知,有时他们不这样做。
为了解决这个问题,我在模型(和表单)中插入了一个名为 *repeat_email* 的额外字段,以防止拼写错误。然后,在验证过程中,验证所有字段后,我使用全局验证器来比较两个字段的数据。
这可行,但我不想将电子邮件在数据库中存储两次(我不想要 *repeat_email*)。是否有任何机制可以在验证过程中使用它,但不将其存储在数据库中?
谢谢,
I am working with Symfony 1.4 and Doctrine. I have a model A with an email field. The form of A displays an input in which the user should insert the email correctly. But as everybody knows, sometimes they don't do it.
To fix this I have inserted an extra field in the model (and in the form), called *repeat_email* to prevent the misspellings. Then, in the validation process, after validating all the fields, i use a global validator to compare the data of the two fields.
This works, but I don't want to have the email stored two times in the database (I don't want the *repeat_email*). Is there any mechanism to use it in the validation process, but not to store it in the database?
Thanks,
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
从模型架构中删除repeat_email字段,并像这样配置您的表单:
Remove repeat_email field from the model schema, and configure your form like this:
错误可能是在模型中添加了额外的字段。您只需要以表格形式提供。
the mistake was probably to add an additional field in the model. You only need it in the form.