<% // ============================================ // the content of this page // ============================================ function Content ( ) { Out ( '<td width="20%"> </td>' ); Out ( '<td width="60%">' );
// if the form has an email address, validate it first // so that if it fails we can show the form to fix var sEmail = ""; var bSubmitted = (Request.Form.Count > 0);
// has the form been submitted? if ( bSubmitted ) { // get the email address from the form... sEmail = "" + Request.Form ( "email" );
// validate the email address and moan if it fails if ( !IsValidEmail ( sEmail ) ) { Out ( '<h5><font color="red">"' + sEmail + '" <i>appears</i> to be an invalid email address - please try again!</font></h5>' ); Out ( '<p><font color="red">If you disagree, please <a href="Contact.asp">contact me</a> directly.</font><p>' ); // pretend the form hasn'\t been sent yet bSubmitted = false; } }
// show the form if not submitted yet if ( !bSubmitted ) { Out ( 'If you\'re interested in hearing whenever a new article is posted, or an existing one is updated, type in your email address below and hit <b>Subscribe!</b>' ); Out ( '<p>Whenever you want to stop receiving my emails, guess what? That\'s right, enter your email address and hit <b>Unsubscribe</b>...' ); Out ( '<p><i>Your email address will never sold to or otherwise used by any third party, just me.</i>' );
// here's the form tag. the action attribute is the name of // the file that will be called with the answer - in this case // it's the same page. the method can be "post" to send the // form data 'behind the scenes' or "get" to appending the // data to the URL in the style page.asp?data1=a&data2=b // // use post most of the time - it's neater and "get" is limited // in the amount of data that can be sent. Out ( '<center><form action="Subscribe.asp" method="post">' );
// another table to line up the titles and inputs Out ( '<table border="0" cellpadding="0">' ); Out ( '<tr><td align="right" valign="top">' ); Out ( 'Email:' ); Out ( '</td><td align="left" valign="top">' ); // a simple text box. we'll reference it with the name "name" // and show 22 characters on the form. use the maxlength // attribute to set the maximum characters they can enter. // use value="some text" to pre-fill the input with data. // // IMPORTANT! using names that are commonly used by // other web sites has a big advantage to the user - IE // will drop down a list of previous answers, which they // can usually pick from rather than type in. Think about this. Out ( '<input type="text" name="email" size="31" value="' + sEmail + '"></input>' ); Out ( '</td></tr>' );
Out ( '<tr><td align="right" valign="top">' ); Out ( ' ' ); Out ( '</td><td align="left" valign="top">' ); // type='submit" provides a submit button to perform the // form action. the button says "Submit" unless you override // with the value attribute. Out ( '<input type="submit" name="action" value="Subscribe"></input> <input type="submit" name="action"