📄 asp_inputforms.asp@output=print
字号:
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html lang="en-US" xml:lang="en-US" xmlns="http://www.w3.org/1999/xhtml">
<head>
<title>ASP Forms</title>
<link rel="shortcut icon" href="../favicon.ico" type="image/x-icon" />
<meta http-equiv="Content-Type" content="text/html; charset=ISO-8859-1" />
<meta name="Keywords" content="xml,tutorial,html,dhtml,css,xsl,xhtml,javascript,asp,ado,vbscript,dom,sql,colors,soap,php,authoring,programming,training,learning,beginner's guide,primer,lessons,school,howto,reference,examples,samples,source code,tags,demos,tips,links,FAQ,tag list,forms,frames,color table,w3c,cascading style sheets,active server pages,dynamic html,internet,database,development,Web building,Webmaster,html guide" />
<meta name="Description" content="Free HTML XHTML CSS JavaScript DHTML XML DOM XSL XSLT RSS AJAX ASP ADO PHP SQL tutorials, references, examples for web building." />
<meta http-equiv="pragma" content="no-cache" />
<meta http-equiv="cache-control" content="no-cache" />
<script type="text/javascript">
var gaJsHost = (("https:" == document.location.protocol) ? "../../https@ssl./default.htm" : "../../www./default.htm");
document.write(unescape("%3Cscript src='" + gaJsHost + "google-analytics.com/ga.js' type='text/javascript'%3E%3C/script%3E"));
</script>
<script type="text/javascript">
var pageTracker = _gat._getTracker("UA-3855518-1");
pageTracker._initData();
pageTracker._trackPageview();
</script>
</head>
<body>
<p>From <b>http://www.w3schools.com</b> (Copyright Refsnes Data)</p>
<h1>ASP Forms and User Input</h1>
<a href="asp_procedures.asp"><img alt="previous" border="0" src="../images/btn_previous.gif" width="100" height="20" /></a>
<a href="asp_cookies.asp"><img alt="next" border="0" src="../images/btn_next.gif" width="100" height="20" /></a>
<hr />
<p class="intro">The Request.QueryString and Request.Form commands may be used to retrieve information from forms, like
user input.</p>
<hr />
<h2>Examples</h2>
<p><a target="_blank" href="showasp.asp@filename=demo_reqquery">A form with
method="get"</a><br />
How to interact with the user, with the Request.QueryString command.</p>
<p><a target="_blank" href="showasp.asp@filename=demo_simpleform">A form with
method="post"</a><br />
How to interact with the user, with the Request.Form command.</p>
<p><a target="_blank" href="showasp.asp@filename=demo_radiob">A form with radio buttons</a><br />
How to interact with the user, through radio buttons, with the Request.Form command.</p>
<hr />
<h2>User Input </h2>
<p>The Request object may be used to retrieve user information from forms.</p>
<p><b>Form example:</b></p>
<table class="ex" cellspacing="0" border="1" width="100%">
<tr>
<td>
<pre><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></pre>
</td>
</tr>
</table>
<p>User input can be retrieved in two ways: With Request.QueryString or Request.Form. </p>
<hr />
<h2>Request.QueryString</h2>
<p>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.</p>
<p>If a user typed "Bill" and "Gates" in the form example
above, the URL sent to the server would look like
this:</p>
<table class="ex" cellspacing="0" border="1" width="100%">
<tr>
<td>
<pre>http://www.w3schools.com/simpleform.asp?fname=Bill&lname=Gates</pre>
</td>
</tr>
</table>
<p>Assume that the ASP file "simpleform.asp" contains the following script:</p>
<table class="ex" cellspacing="0" border="1" width="100%">
<tr>
<td>
<pre><body>
Welcome
<%
response.write(request.querystring("fname"))
response.write(" " & request.querystring("lname"))
%>
</body></pre>
</td>
</tr>
</table>
<p>The browser will display the following in the body of the document:</p>
<table class="ex" cellspacing="0" border="1" width="100%">
<tr>
<td>
<pre>Welcome Bill Gates</pre>
</td>
</tr>
</table>
<br />
<hr />
<h2>Request.Form </h2>
<p>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.</p>
<p>If a user typed "Bill" and "Gates" in the form example
above, the URL sent to the server would look like
this: </p>
<table class="ex" cellspacing="0" border="1" width="100%">
<tr>
<td>
<pre>http://www.w3schools.com/simpleform.asp</pre>
</td>
</tr>
</table>
<p>Assume that the ASP file "simpleform.asp" contains the following script:</p>
<table class="ex" cellspacing="0" border="1" width="100%">
<tr>
<td>
<pre><body>
Welcome
<%
response.write(request.form("fname"))
response.write(" " & request.form("lname"))
%>
</body></pre>
</td>
</tr>
</table>
<p>The browser will display the following in the body of the document:</p>
<table class="ex" cellspacing="0" border="1" width="100%">
<tr>
<td>
<pre>Welcome Bill Gates</pre>
</td>
</tr>
</table>
<br />
<hr />
<h2>Form Validation</h2>
<p>User input should be validated on the browser whenever possible (by client scripts).
Browser validation is faster and you reduce the server load.</p>
<p>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.</p>
<hr />
<a href="asp_procedures.asp"><img alt="previous" border="0" src="../images/btn_previous.gif" width="100" height="20" /></a>
<a href="asp_cookies.asp"><img alt="next" border="0" src="../images/btn_next.gif" width="100" height="20" /></a>
<p>From <b>http://www.w3schools.com</b> (Copyright Refsnes Data)</p>
</body>
</html>
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -