Form Sample

NOTE: This is an example of doing "Server-side Validation".

<% @ Language="JavaScript" %>

<HTML>
<HEAD><TITLE>
Form Sample</TITLE></HEAD>

<BODY>

<H3>Form Sample</H3>

<HR>

<%

// CONTENT_LENGTH will only be greater than 0
// if we Submitted a Form using the POST Method.
// If this is the case then display the results
// Else Display the Form for the User to fill out.
if (Request.ServerVariables("CONTENT_LENGTH") == 0) {

%>

This sample shows how to use the Request collection to get information from a posted form.

<FORM METHOD="POST" ACTION="form.asp">
     Your Name: <INPUT TYPE="TEXT" NAME="name">
     Movies that you like: (you may select more than one)
     <SELECT NAME="movies" MULTIPLE SIZE="3">
          <OPTION VALUE="Star Wars">Star Wars</OPTION>
          <OPTION VALUE="Antz">Antz</OPTION>
          <OPTION VALUE="Gone with the Wind">Gone with the Wind</OPTION>
     </SELECT>
     Why do you like the movies you've selected?
     <TEXTAREA NAME="describe"></TEXTAREA>
     <INPUT TYPE="Submit" NAME="Submit Form">
     <INPUT TYPE="Reset" NAME="Reset Form">
</FORM>

<%
}
else {
     if (Request("name") == "") { // if the name field is empty notify the user
%>

You did not provide your name.

<%
     }
     else { // if the name field isn't empty then write their name
%>

Your name is <B><% = Request("name")  %></B>

<%
     }
%>

<%
    
// because the Select Object is set to Multiple the User can choose 1, 2, or 3 items
     // Count is a property of the Request when Multiple items can be selected, ie, checkboxes
     // if the Count equals 0 we know that the User didn't select any movies
     if (Request("movies").Count == 0) {
%>

You did not select any movies.

<%
     }
     else {
%>

The movies you like are: <B><% = Request("movies")  %></B>

<%
         
// if the User didn't give a reason why he/she liked the movie(s) then notify the User
          if (Request("describe") == "") {
%>

You did not say why you like the movie(s) you have selected.

<%
          }
          else {
%>

Your description of why you like the movie(s) is:

NOTE: if the User gave a reason why he/she liked the movie(s) then write this out
<I><B><% = Request("describe")  %></B></I>

<%
          }
%>

<%
     }
%>

<%
}
%>

</BODY>
</HTML>