drupal javascript API 和表单设置错误
1.有没有办法在客户端执行 form_set_error ,以便如果 javascript 验证中出现错误,它将设置错误并且不会让用户处理其他步骤? js 可以被禁用,所以我要格外小心...
哪里有像 Drupal.t 之类的 drupal javascript 函数参考的完整列表?
如何更改表单集错误的错误消息(默认错误如 { fieldname... field is required } ?
如何执行在字段下方/上方/内联显示的错误?
1.is there a way to do form_set_error in client side so if there is error in javascript validate it will set error and wont let user process the other steps? js can be disabled so i want to take extra caution...
where is a complete list of drupal javascript function reference like Drupal.t and stuff?
how can i change the error messages of form set error (the default errors like { fieldname... field is required } ?
how can i do errors that will show below/above/inline the field ?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
Drupal 中的 JavaScript,涵盖了 Drupal JavaScript API、AHAH 表单以及您正在寻找的内容。 快速入门指南非常好。
至于验证,你是对的,Javascript 可以关闭。 JavaScript 验证主要是为了可用性,因为用户不必等待 POST 表单来接收错误消息。 JavaScript 会在提交表单之前实时通知他,例如他的密码太弱或电子邮件无效。
然而 JavaScript 验证并不利于安全。这就是您需要进行服务器端验证的地方。 form_set_error 将负责服务器 -侧面验证。
因此,如果您有一个如下所示的表单:
服务器端验证将如下所示:
如果表单中的栏文本字段确实为空,则当用户提交表单时,栏将突出显示,“Foo 不能为空”错误消息将出现,并且不会调用表单 _submit 挂钩。
对于 JavaScript 功能,Drupal JavaScript API 概述文档包含您需要的大部分信息。
JavaScript in Drupal, Covers the Drupal JavaScript API, AHAH forms, and the kind of stuff your looking for. The Quick start Guide is pretty good.
As for validation, you're right, Javascript can be turned off. JavaScript validation is mostly done for usability, since the user doesn't have to wait to POST his form in order to receive an error message. JavaScript lets him know in real time if for example, his password is too weak, or email invalid, before submitting the form.
JavaScript validation however is not good for security. That's where you will need to do server-side validation. form_set_error will take care of the server-side validation.
So if you have a form that looks like:
The server-side validation would look like:
If the bar textfield in the form is indeed empty, when the user submits the form bar will be highlighted, the 'Foo cannot be empty' error message will appear, and the form _submit hook won't be called.
For JavaScript functionality, the Overview of Drupal JavaScript API document has most of the information you will need.