Home Articles FAQs XREF Games Software Instant Books BBS About FOLDOC RFCs Feedback Sitemap
irt.Org
#

Q5814 How can I access the values of a form submitted to my ASP page?

You are here: irt.org | FAQ | ASP | Q5814 [ previous next ]

The form tag has an attribute callled 'method' with two values 'get' and 'post'.

These two submission methods provide the form's data in different ways that you will choose based on your needs.

GET: This provides the contents of the form embedded in the URL that you pass to the processing page. These values are retrieved using the Request.Querystring collection (Example 1). Note how since the Querystring is a collection, you can loop through all the form's fields showing their name and value. It also loops through all the values for the 'car' field.

POST: Field contents are passed without being embedded in the URL. In Example 2, the only difference is that the Request.Form collection is used in place of Request.Querystring.

<%
' EXAMPLE 1: GET METHOD

' SET THE FLAG VALUE IF NOT IN THE QUERYSTRING
flag = Request.QueryString("flag")
If flag = "" Then
	flag = 1
End If

' EITHER DISPLAY THE FORM TO GIVE INPUT (CASE 1)
' OR VIEW THE FIELDS PASSED (CASE 2)
Select Case flag
Case 1 %>
	<form name='myForm' action='form.asp' method='get'>
	<input type='text' name='car' size='35' value='Fiat'>
	<input type='text' name='car' size='35' value='Porche'>
	<input type='hidden' name='flag' value='2'>
	<input type='submit' value='Submit'>
</form>

<% Case 2
' LOOP THROUGH EACH VALUE AND DISPLAY IT
For each inputField in Request.QueryString
	For each inputValue in Request.QueryString(inputField)
		response.write inputField  & " = " & inputValue & "<
		br>"
	Next
Next
End Select
%>

<%
' EXAMPLE 2: POST METHOD

flag = Request.Form("flag")
If flag = "" Then
	flag = 1
End If

Select Case flag
Case 1 %>
	<form name='myForm' action='forms.asp' method='post'>
	<input type='text' name='car' size='35' value='Fiat'>
	<input type='text' name='car' size='35' value='Porche'>
	<input type='hidden' name='flag' value='2'>
	<input type='submit' value='Submit'>
</form>

<% Case 2
' LOOP THROUGH EACH VALUE AND DISPLAY IT
For each inputField in Request.Form
	For each inputValue in Request.Form(inputField)
		response.write inputField  & " = " & inputValue & "<
		br>"
	Next
Next
End Select
%>

©2018 Martin Webb