Form validation/zh-cn: Difference between revisions

From Joomla! Documentation

Created page with "服务器端校验"
Created page with "当用户提交表单后系统会触发服务器端校验程序,如果校验失败,系统会将该字段校验失败的信息展示给用户。 <br/>为了让系统明白..."
Line 8: Line 8:


服务器端校验
服务器端校验
.. is done after having submitted the form and will normally return to the form when not validated with some extra messages. <br/>
当用户提交表单后系统会触发服务器端校验程序,如果校验失败,系统会将该字段校验失败的信息展示给用户。 <br/>为了让系统明白哪一个字段需要校验,你需要在HTML中进行标记。标记的方法是在输入框中增加 '''attributes''' <u>required</u> ("true" or "required") and <u>validate</u> (required表示该字段是必须的,validate用来指明校验的程序; 例如. validate="email" 那么就会调用email这个规则来进行校验)
It uses the HTML '''attributes''' <u>required</u> ("true" or "required") and <u>validate</u> (with value being a joomla or custom rule; e.g. validate="email")


More here: [[S:MyLanguage/Server-side form validation|Server-side form validation]]
More here: [[S:MyLanguage/Server-side form validation|Server-side form validation]]

Revision as of 14:15, 15 September 2017

Joomla的表单验证包括客户端和服务端。服务器端是必须要有的,这样能够确保你的数据是经过校验的,因为用户端的数据总是不可信的。客户端虽然不能够百分百的保证数据的有效性,但是它对于改善用户体验是非常有帮助的。因此,我们强烈建议你将两端都实现校验。

客户端校验 客户端的校验是通过javascript脚本来实现的,当用户在输入框中输入数据的时候会触发校验(一般是响应onblur事件,当输入框失去焦点时)。为了让系统知道哪一个字段需要被校验,你需要在你的输入框中增加两个类 required and validate-[xxx](其中[XXX]代表了joomla系统内置或者用户自定义的校验规则。如:validate-numeric)

更多信息: Client-side form validation

服务器端校验 当用户提交表单后系统会触发服务器端校验程序,如果校验失败,系统会将该字段校验失败的信息展示给用户。
为了让系统明白哪一个字段需要校验,你需要在HTML中进行标记。标记的方法是在输入框中增加 attributes required ("true" or "required") and validate (required表示该字段是必须的,validate用来指明校验的程序; 例如. validate="email" 那么就会调用email这个规则来进行校验)

More here: Server-side form validation