ASP/.NET Web Hosting
* 3 Months FREE *
CLICK HERE!
 CoverYourASP --> Implementing forms with ASP --> Part 5

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
62 active users
3083 visitors today
5605 pages today
(only part of today)
Tools I use

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

ASP.NET Blog
RSS submissions
E-commerce

Now open source with SourceForge!

Processing the data

Now that we're nearly finished, let's review the framework code once more. Hopefully this time through you'll recognise the code that I've explained up to this point:

var bSubmitted = (Request.Form.Count > 0);
var sName = 'egghead';

// has the form been submitted?
if ( bSubmitted )
{
   // get the data from the form...
   sName = ''  + Request.Form ( "name" );

   // validate the name
   if ( !sName.length )
   {
      Out ( 'You must enter a name<p>' );

      // pretend the form hasn't been sent yet
      bSubmitted = false;
   }
}

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

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

      Out ( 'Name: ' );
      Out ( '<input type="text" name="name" size="10" value="' + sName + '">' );
      Out ( '<input type="submit" value="Display name">' );

   Out ( '</form>' );
}
else
{
   // process data
   Out ( 'Hi ' + sName );
}

If the form was submitted, validate the data. If not submitted yet, or if any validation failed, display the form. Only if the form was submitted successfully process the data.

This last step, here just displaying the users name, is where the real work of the form is done. Storing sName to a database table, sending sName to someone in an email or many other tasks could all be performed here.

Since the variables are all set up and ready to be used there is no form-specific code needed - you could simply call my SendEmail( ) function and perhaps pass in variables from the form: sEmail, sFrom, sBody, etc. There are many examples of forms on this site - just choose Search from the navigation bar and enter "form"!

Featured sponsor
My favorite resources

Tiki Statues - Tiki Masks - Tiki Totems


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?


New Proposal Kit Professional 5.1
Brand yourself as a top professional: create quotes and amazing proposals and get many legal documents free!

The latter saved me 3 times the purchase price on the first day I owned it!