Open In App
Related Articles

ASP Request.Form Collection

Improve Article
Improve
Save Article
Save
Like Article
Like

The Request.Form Collection in ASP is used for returning the collection of form elements that posted to the HTTP request body, with a form using the POST method. 

Syntax

Request.Form( element )[(index)|.Count]

Parameter:

  • Element: It specifies the name of the form elements. It is a required attribute.
  • Index: It is an optional parameter that represents a position of form elements that used to access. It can be any integer from 1 to n.

Example 1: Below code uses the for loop to access the form values filled by the user. We could retrieve those values like this: 

PHP




<% 
for i=1 to Request.Form("color").Count
 Response.Write(Request.Form("color")(i) & "<br>")
next
%>


Output: 

Blue
Green

Example 2: 

HTML




<form action="submit.asp" method="post">
    <p>First name: <input name="firstname"></p>
    <p>Last name: <input name="lastname"></p>
  
    Your favorite game:
    <select name="game">
    <option>Hockey</option>
    <option>Cricket</option>
    <option>FootBall</option>
    <option>Golf</option>
    <option>Basket Ball</option>
</select>
  
<p><input type="submit"></p>
</form>


Following Values filled by the user:

firstname=naman&lastname=jain&game=cricket

Here is the ASP code that is used to retrieve the information from the form. 

PHP




Hello <%=Request.Form("firstname")%>.  
Your favorite game is <%=Request.Form("game")%>.


Output

Hi, Naman. Your favorite game is Cricket

Whether you're preparing for your first job interview or aiming to upskill in this ever-evolving tech landscape, GeeksforGeeks Courses are your key to success. We provide top-quality content at affordable prices, all geared towards accelerating your growth in a time-bound manner. Join the millions we've already empowered, and we're here to do the same for you. Don't miss out - check it out now!

Last Updated : 03 Feb, 2021
Like Article
Save Article
Previous
Next
Similar Reads
Complete Tutorials