Zend 框架 - 定制表单验证
我做了一个多页表单,但我没有使用子表单 - 只是将数据保存在 mySQL 中。
我想在每个表单上使用验证器,但即使验证失败也允许表单提交。我想使用验证器在我的数据库中发布一个标志来说明表单是否通过或未通过验证。
这样做的原因是允许每个表单在几周内更新,但所有表单的最终提交取决于每个单独的表单是否经过验证(根据数据库中设置的标志)。
任何提示都将受到赞赏,特别是在修改验证脚本方面。
I doing a multi page form, but I'm not using sub form - just persisting the data in mySQL.
I want to use validators on each form, but to allow the form to submit even if validation fails. I want to use the validators instead to post a flag in my database to say whether or not the form passed or failed validation.
The reason for this is to allow each form to be updated over a period of weeks, but the final submission of all the forms is then subject to whether each separate form validated (according the the flag set in the database).
Any tips would be apprecited, especially on modifying the validation script.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
我认为你不需要修改任何东西。
Zend 不支持 JavaScript 表单验证,它是在服务器端完成的,因此无论如何都会提交表单并生成 POST/GET 数据。仅在您的操作中调用
$form->isValid($_POST);
您提交初步步骤和最终步骤的操作应该不同,例如
processPreliminaryAction()< /code> 和
processFinalAction()
。在初步步骤中,您可以迭代提交的表单元素并对每个元素调用 isValid(),然后您可以在 MySQL 中保存该字段是否有效及其值。
在最终提交中,您对整个表单调用
isValid()
,并且仅当它为 TRUE 时才继续执行您需要执行的操作。I don't think you need to modify anything.
Zend doesn't to JavaScript form validation, it is done server-side, so a form is submitted and POST/GET data is generated regardless. It is only in your action that you call
$form->isValid($_POST);
The action you are submitting your preliminary and final steps should be different, such as
processPreliminaryAction()
andprocessFinalAction()
.In your preliminary steps, you can iterate through submitted form Elements and call
isValid()
on each element, then you can save whether or not the field was valid in MySQL along with its value.In your final submission, you call
isValid()
on the entire form and proceed with what you need to do only if it is TRUE.