Wife/Girlfriend/Sister?
Pepper Spray &
Stun Gun Specials!
KEEP THEM SAFE.
 CoverYourASP --> Implementing forms with ASP --> Part 3

Free membership

Join in the fun! Sign in
Member Services

Site navigation
Download the entire site!
Search my articles
Free Magazines
Browse the directory

Send me feedback
Buy my boxer shorts

Recommend this page
Printer-friendly page

Resources I recommend
Link to my site
Advertising slashed!
About your privacy
Legal stuff
Site statistics
87 active users
254 visitors today
505 pages today
(only part of today)
Tools I use

CoverYourASP
Copyright © 1999-2010 James Shaw.
All rights reserved.

ASP.NET Blog
RSS submissions
E-commerce

Now open source with SourceForge!

Displaying the form

// show the form if not submitted yet
if ( !bSubmitted )
{
   Out ( 'Here\'s a simple form.' );

So, on to displaying the form. In this case I want to display the form only when the form hasn't been submitted yet, but of course you could remove the "if" and display the form again every time - my search form does that.

Note that as discussed earlier, bSubmitted will also be false if the form has been submitted with invalid data, so the form will refresh with the submitted values intact, ready for the user to fix the errors.

   Out ( '<form action="FormPage.asp" method="post">' );

The <form< tag has two main attributes - action and method.

action defines which page to call when the form is submitted. You can hardcode your page name as I have, or you can make the form easier to maintain by using the name of the current page held in the ServerVariables collection, as shown below:

   Out ( '<form action="' + Request.ServerVariables ( 'SCRIPT_NAME' ) + '" method="post">' );

Note that the ServerVariables collection is quite "expensive" the first time you use it on a page - although it contains many useful values, please use sparingly.

The method attribute can have two values, get and post. Only in very rare cases will you want to use get - since it uses the URL to submit the values it is limited to 255 characters of data, is very insecure, and ugly!

post, on the other hand, passes the values in the HTTP headers where it cannot be seen, and the limit is much higher.

Part 4: <form> inputs...

Featured sponsor
My favorite resources

Tiki Statues - Tiki Masks - Tiki Totems



See my source code
wherever you see this icon...

You can also download the entire site source code for FREE!

CoverYourASP Mugs, T-shirts, caps - even Boxer shorts...
I don't make a penny from these, but they're a lot of fun! Don't you need a new mouse mat?