Drupal 向导表单:验证和上一个按钮
在我的 drupal6 站点中,我有向导形式。 我使用表单存储和重建属性通过 FormAPI 实现了它。 我的表单验证是使用 #required 属性和 #element_validate 属性中的函数完成的。 它工作正常,但一方面,当我单击上一个按钮时,表单正在被验证,但我不希望它被验证。 单击表单的特定按钮时是否有一种聪明且正确的方法来禁用验证?
In my drupal6 site I have wizard form. I implemented it with FormAPI using form storage and the rebuild property. My form validation is being done with the #required property and with functions in the #element_validate property. It's working fine but for one thing, when I click on the previous button the form is being validated and I don't want it to. Is there a smart and right way to disable the validations when a specific button of the form is clicked?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
干净地执行此操作的唯一方法(不幸的是)是避免使用 #required = TRUE 并在验证处理程序中自行验证它,同时考虑到表单在向导过程中处于哪个“步骤”。
一种常见的方法是将所有正在进行的数据累积在 $form_state['storage'] 中,这些数据将在重建之间保留下来。
The only way to do this cleanly (unfortunately) is to avoid the use of #required = TRUE and validate it yourself in a validation handler, taking into account knowledge of what 'step' the form is on in the wizard process.
One common approach is to accumulate all of your in-progress data in $form_state['storage'], where it will persist between rebuilds.
凯文的回答有效。 您还可以尝试http://drupal.org/project/skip_validation,您可以在其中添加额外的属性您之前的按钮,
'#skip_validation' => 正确
Kevin's answer works. You could also try http://drupal.org/project/skip_validation where you would add an additional property to your previous button,
'#skip_validation' => TRUE