验证 Drupal 表单中的输入
我有一个 Drupal 表单,其中有人输入信息,我需要在提交之前进行数据库查询以检查它是否有效。我希望有一个按钮,用户可以单击来检查有效性(或者在用户离开该字段后自动完成),然后显示有关他的选择的一些信息。
我知道我可以在提交表单时使用 hook_form_submit 来检查表单,然后在出现任何错误时停止该过程,但我希望用户能够在提交表单之前确认他们选择了正确的内容。
I have a Drupal form wherein someone inputs information, and I need to do a database query to check if it is valid before submitting. I would like to either have a button the user can click to check the validity (or have it be done automatically after the user leaves that field), and then display some information about his selection.
I know I can use hook_form_submit to review a form when it is submitted and then stop the process if there are any errors, but I would like the user to be able to confirm they have selected the correct thing before submitting the form.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
我还没有亲自尝试过这个模块,但它可能就是您正在寻找的:
http://drupal.org /project/ajax
如果您只是在寻找一种实时查找的方法(例如输入图书条形码并获取标题),您也可以使用 Drupal 的自动完成功能,但它需要您编写您自己的自动完成功能来处理数据库查找。
I haven't personally tried this module, but it might be what you're looking for:
http://drupal.org/project/ajax
If you're just looking for a way to do real-time lookups (e.g. entering the book barcode and getting the title), you can also use Drupal's autocomplete feature, but it will require you to write your own autocomplete function to handle the database lookups.
看一下:带有验证处理程序的基本表单。您实际上只需要添加一个类似于 mymodule_myform_validate($form, &$form_state) { ... } 的函数。从链接页面:
“这添加了一个新的表单字段以及一种使用验证函数(也称为验证处理程序)对其进行验证的方法。”
Take a look at: Basic form with validate handler. You really just need to add a function similar to
mymodule_myform_validate($form, &$form_state) { ... }
. From the linked page:"This adds a new form field and a way to validate it with a validate function, also referred to as a validate handler."