Setting up the display and email validation functionsHere we will only set up 2 functions. One will display the form that will hide your email address and the other will check the format of an email address. We will just manually add some very basic html to display the pages. I have added copious comments to all of the code to explain what is happening in it. Let's get started. The first thing I want you to do is to open your form_output_fns.php file with your text editor, and copy the code below and paste it into form_output_fns.php, then save it. I have colored the code here so you can see the comments better, so take a real close look at it to see what you have done. <?php // Start Parsing PHP// Then display the email form, along with the variables to be validated or displayed in the form fields function display_email_form($f_name,$l_name,$e_mail,$subject,$content) { // Start the code block ?> <!-- Stop the PHP Parser to display the form in good ol html. --> <!--Everything below is nothing more than a standard html form except php values are included to keep the variable values alive and pre-populate the form boxes if a visitor is sent back to fix an error --> <table border="0" align="center" summary=""> <form action="email_form_2.php" method="post"> <!-- Putting the form inside the table tags prevents old Netscape browsers from crashing --> <tr> <th colspan="2"><font color="#FF0000"><b>*</b></font>Required Fields</th> </tr> <tr> <td align="right"><font color="#FF0000"><b>*</b></font>First Name </td> <td align="left"> <input type="text" name="f_name" size="30" maxlength="40" value="<?php echo $f_name; ?>"></td> </tr> <tr> <td align="right"><font color="#FF0000"><b>*</b></font>Last Name </td> <td align="left"><input type="text" name="l_name" size="30" maxlength="40" value="<?php echo $l_name; ?>"></td> </tr> <tr> <td align="right"><font color="#FF0000"><b>*</b></font>Email</td> <td align="left"><input type="text" name="e_mail" size="40" maxlength="40" value="<?php echo $e_mail; ?>"></td> </tr> <tr> <td align="right"><font color="#FF0000"><b>*</b></font>Subject </td> <td align="left"><input type="text" name="subject" size="25" maxlength="40" value="<?php echo $subject; ?>"></td> </tr> <tr> <td align="right" valign="middle"><font color="#FF0000"><b>*</b></font>Email Body </td> <td align="left"><textarea name="content" cols="41" rows="10" wrap="virtual"><?php echo $content; ?></textarea></td> </tr> <tr> <td align="right"> </td> <td align="left"><input type="submit" value="Send Email"> <input type="reset" value="Reset"><br><br></td> </tr> </form> </table> <?php // Start the PHP parser again to end the code block } // End the code block // PHP is still running from above so we don't need to start it again. // This function validates the format of an email address. function valid_email($e_mail) { // Start the code block // If it doesn't match the pattern below, False is returned and input is rejected. if (ereg("^[a-zA-Z0-9_\.\-]+@[a-zA-Z0-9\-]+\.[a-zA-Z0-9\-\.]+$", $e_mail)) return true; else return false; } // End the code block /*We could close the PHP parser now, but it is not necessary since the valid email function automatically returns to the point where it was activated on my_email_form_2.php.*/
|