Wife/Girlfriend/Sister?
Pepper Spray &
Stun Gun Specials!
KEEP THEM SAFE.
 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
17 active users
1 visitor today
3 pages today
how is this done?
Tools I use

CoverYourASP
Copyright © 1999-2012 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



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

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


I share my content

Supporting ASPRSS

Do you need a quick and easy way to link to my articles? All the information you need is published with ASPRSS...