« 突破iis6.0上传文件的200kb限制Access命令行参数 »

ASP表单与用户输入区域

来自:w3schools  翻译:Linyupark

The Request.QueryString and Request.Form commands may be used to retrieve information from forms, like user input.
Request.QueryString 和 Request.Form 命令可用来从表单上获取信息,如用户的输入信息。
Examples
举例

A form with method="get"
How to interact with the user, with the Request.QueryString command.
怎样使用 Request.QueryString 命令与用户互动

A form with method="post"
How to interact with the user, with the Request.Form command.
怎样使用 Request.Form 命令与用户互动

A form with radio buttons
How to interact with the user, through radio buttons, with the Request.Form command.
怎样通过使用单选按钮与 Request.Form 命令来和用户互动。
User Input
用户输入

The Request object may be used to retrieve user information from forms.
Request对象用于获取来自表单的用户信息。

Form example:
表单举例:

<form method="get" action="simpleform.asp">
First Name: <input type="text" name="fname" />
<br />
Last Name: <input type="text" name="lname" />
<br /><br />
<input type="submit" value="Submit" />
</form>

User input can be retrieved in two ways: With Request.QueryString or Request.Form.
用户的输入信息可以有两种方法获取:With Request.QueryString 或 Request.Form
Request.QueryString

The Request.QueryString command is used to collect values in a form with method="get". Information sent from a form with the GET method is visible to everyone (it will be displayed in the browser''s address bar) and has limits on the amount of information to send.
Request.QueryString 命令用来收集使用method="get"的表单中的值集。信息从表单以GET的方式发送对于任何来说都是可见的信息(它会在浏览器的地址栏中显示出来)并且它所能发送的信息量是有限制的。

If a user typed "Bill" and "Gates" in the form example above, the URL sent to the server would look like this:
如果用户在上面的表单中打入了"Bill" 和 "Gates",被发送到服务器上的URL看上去就会像这样:

http://www.w3schools.com/simpleform.asp?fname=Bill&lname=Gates

Assume that the ASP file "simpleform.asp" contains the following script:
假设这个名为"simpleform.asp"的ASP文件包含以下脚本:

<body>
Welcome
<%
response.write(request.querystring("fname"))
response.write(" " & request.querystring("lname"))
%>
</body>

The browser will display the following in the body of the document:
浏览器上将会显示出以下内容:

Welcome Bill Gates


Request.Form

The Request.Form command is used to collect values in a form with method="post". Information sent from a form with the POST method is invisible to others and has no limits on the amount of information to send.
Request.Form 命令被用来收集表单发送形式为"post"的值集。信息以这种方式发送其内容对于外人来讲是不可见的,并且没有信息量上的限制。

If a user typed "Bill" and "Gates" in the form example above, the URL sent to the server would look like this:
如果用户在上面的举例的表单中打入"Bill" 和 "Gates",被发送到服务器上的URL是这样的(无额外的内容):

http://www.w3schools.com/simpleform.asp

Assume that the ASP file "simpleform.asp" contains the following script:
假设 "simpleform.asp" 文件包含以下脚本:

<body>
Welcome
<%
response.write(request.form("fname"))
response.write(" " & request.form("lname"))
%>
</body>

The browser will display the following in the body of the document:
那浏览器上会显示以下内容:

Welcome Bill Gates


Form Validation
表单确认

User input should be validated on the browser whenever possible (by client scripts). Browser validation is faster and you reduce the server load.
用户的输入信息应该尽可能的在浏览器上进行校验(通过客户脚本)。这样能更为快速并且能减少服务器的负担。

You should consider using server validation if the user input will be inserted into a database. A good way to validate a form on the server is to post the form to itself, instead of jumping to a different page. The user will then get the error messages on the same page as the form. This makes it easier to discover the error.
如果用户所要校验的信息是在数据库里的,那应该要考虑使用服务端的校验。让表单在当前页面进行与服务端的校验工作是个比较好的方法,相比发送到别的页面它来的更为方便让用户知道错误的位置。

原创文章如转载,请注明:转载自悠悠博客 [ http://www.ajaxstu.com/ ]

相关文章:

发表评论:

◎欢迎参与讨论,请在这里发表您的看法、交流您的观点。