Visit the Official PHP Website

Search this Site

PHP Programming

By James N Hitz

The Code

Our code that actually tests the form input to validate and process is as follows:

<html><head><title>Your Suggestions</title>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1"></head>
<body bgcolor="black" text="white">
<center>
<?php
 if(trim($fName) ==""){
   $missing =  "<p>The <b>First Name</b> has not been provided.";
 }elseif(!preg_match("/^\w+$/", $fName)){
   $missing .= "<p><b>First Name</b> contains invalid character(s)";
 } 

 if(!preg_match("/^\w+$/",$lName)){
   $missing .= "<p>The <b>Last Name</b> contains invalid character(s)";
 }
	
 if(!preg_match("/^(\w+)\@(\w+)\.(\w){2,3}$/",$eAddress)){
   $missing .= "<p>Invalid <b>Email Address</b> Provided.";
 }
 
 if(trim($suggestion) ==""){
    $missing .= "<p><b>Suggestion</b> is blank.";
 }
	
 if(trim($missing) != ""){
    print "<p>There are a few problems with your data entry:</p>". $missing;
} else {
    print "<h2>Thank You</h2>".
     "<p>Hello <b>". $fName . " " . $lName . "</b><p>Your suggesstions state that".
     "<br><b>$suggestion</b>\.  Your email address <b>". 
     $eAddress . "</b> is valid";
     }
} 
?>
<center>
</body></html>

<< The Interface | The Code Explained >>

JamHitz Productions