Form validation/zh-cn: Difference between revisions

From Joomla! Documentation

Created page with "表单校验"
 
FuzzyBot (talk | contribs)
Updating to match new version of source page
 
(12 intermediate revisions by one other user not shown)
Line 1: Line 1:
<noinclude><languages /></noinclude>
<noinclude><languages /></noinclude>
Joomla has client-side and server-side form validation capabilities.<br/>
<div class="mw-translate-fuzzy">
Server side validation is the minimum since everything before that can be overridden on the user side. But client-side is the most user-friendly one, so using both is not a bad idea (especially since the latter is unobtrusive and won't give problems on javascript-disabled or -problematic client browsers).
Joomla的表单验证包括客户端和服务端。服务器端是必须要有的,这样能够确保你的数据是经过校验的,因为用户端的数据总是不可信的。客户端校验虽然不能够百分百的保证数据的有效性,但是它对于改善用户体验是非常有帮助的。因此,我们强烈建议你将两端都实现校验。
</div>


==Client-side validation==
==客户端校验==
.. is done via javascript while the user is filling in the form fields.<br/>
客户端的校验是通过javascript脚本来实现的,当用户在输入框中输入数据的时候会触发校验(一般是响应onblur事件,当输入框失去焦点时)。为了让系统知道哪一个字段需要被校验,你需要在你的输入框中增加两个类 <u>required</u> and <u>validate-[xxx]</u>(其中[XXX]代表了joomla系统内置或者用户自定义的校验规则。如:validate-numeric)
It uses the HTML '''classes''' <u>required</u> and <u>validate-[xxx]</u> (with [xxx] being a joomla or custom rule; e.g. validate-numeric)


More here: [[S:MyLanguage/Client-side form validation|Client-side form validation]]
更多信息: [[S:MyLanguage/Client-side form validation|Client-side form validation]]


==Server-side validation==
==服务器端校验==
.. 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]]
<div class="mw-translate-fuzzy">
更多信息: [[S:MyLanguage/Server-side form validation|Server-side form validation]]
Joomla中文技术讨论: [[http://www.joomlachina.cn/social/]]
</div>


<noinclude>
<noinclude>

Latest revision as of 09:32, 31 March 2020

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这个规则来进行校验)

更多信息: Server-side form validation Joomla中文技术讨论: [[1]]