当前位置: 首页 > 网络学院 > 服务端脚本教程 > ASP > ASP Forms

ASP
ASP Drive
ASP File
ASP Folder
ASP Dictionary
ASP ADO
ASP AdRotator
ASP BrowserCap
ASP Content Linking
ASP Content Rotator
ASP Quick Ref
ASP 摘要
ASP 实例

ASP Forms


出处:互联网   整理: 软晨网(RuanChen.com)   发布: 2009-03-01   浏览: 925 ::
收藏到网摘: n/a

The Request.QueryString and Request.Form commands may be used to retrieve information from forms, like user input.
“Request.Querystring”和“Requset.form”指令是用来获取来自“Form”表单的信息的,比如:用户在“Input”中输入的信息。


Examples
实例

A form with method="get"
Method=“get”的表单
How to interact with the user, with the Request.QueryString command.
如何使用“Response.Querystring”与用户进行互动。

A form with method="post"
Method=“post”的表单
How to interact with the user, with the Request.Form command.
如何使用“Response.Form”与用户进行互动。

A form with radio buttons
使用“radio”按钮的表单
How to interact with the user, through radio buttons, with the Request.Form command.
如何通过“radio”按钮和“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
“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”方式发送的表单信息对于所有人来说都是可见的(它将在浏览器的地址栏中被显示出来)。还有一点重要的是,如果选择“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”两个单词,那么发送到服务器上的网址将会出现下面的形式:

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

Assume that the ASP file "simpleform.asp" contains the following script:
在这里,我们假设“simpleform.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
“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”指令用来收集表单中“Method=post”所发送的值。通过“post”方式发送的表单信息对于所有人来说都是不可见的。还有一点值得一提的是,如果选择“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”两个单词,那么发送到服务器上的网址将会出现下面的形式:

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.
如果用户输入的信息要被存入数据库(或是验证的信息是原本就存在数据库里的),那么你就应该考虑在服务器端进行信息验证了。在服务器端验证信息,其中一个比较好的方法就是,在表单所处的当前页上进行验证,而不要跳到新的一页上进行验证。这样做的好处是:可以让用户更容易查到出现错误的位置。

评论 (0) All

登陆 | 还没注册?