Processing the dataNow 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"! |