The great advantage of ASP is possibility to respond to user queries or data submitted from HTML forms. You can process information gathered by an HTML form and use ASP code to make decisions based off this information to create dynamic web pages. In this tutorial we will show how to create an HTML form and process the data.
Before you can process the information, you need to create an HTML form that will send information to your ASP page. There are two methods for sending data to an ASP form: POST and GET. These two types of sending information are defined in your HTML form element’s method attribute. Also, you must specify the location of the ASP page that will process the information.
Below is a simple form that will send the data using the POST method. Information sent from a form with the POST method is invisible to others and has no limits on the amount of information to send. Copy and paste this code and save it as “form.html”.
<title>Process the HTML form data with the POST method</title>
<form method="POST" action="process.asp" name="form1">
<table width="70%" border="0" cellspacing="0" cellpadding="0">
<td colspan="2"><input type="text" name="name"></td>
<td colspan="2"><input type="text" name="email"></td>
<td colspan="2"><textarea name="comment" cols="40" rows="5"></textarea></td>
<td colspan="2"><input type="submit" name="Submit" value="Submit"></td>
Next, we are going to create our ASP page “process.asp” that will process the data. In our example we decided to send data with the POST method so to retrieve the information we can use the ASP ‘Request.From’ command. Copy and paste this code and save it in the same directory as “form.html”.
<%@ Language="VBscript" %>
'declare the variables that will receive the values
Dim name, email, comment
'receive the values sent from the form and assign them to variables
'note that request.form("name") will receive the value entered
'into the textfield called name
'let's now print out the received values in the browser
Response.Write("Name: " & name & "<br>")
Response.Write("E-mail: " & email & "<br>")
Response.Write("Comments: " & comment & "<br>")
Note: If you want to process the information sent through an HTML form with the GET method you should use the ‘Request.QueryString’ command . In the preceding example you should replace all instances of Form with QueryString. But remember that the data 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.