PHP self form validation
<pre>
<p>&lt;?php</p>
<p>function VerifyForm(&amp;$values, &amp;$errors) 
  { 

  if (strlen($values['fname']) == 0) 
  $errors['fname'] = 'Enter First Name'; 

  if (strlen($values['lname']) == 0) 
  $errors['lname'] = 'Enter Last Name'; 

  if (strlen($values['mname']) == 0) 
  $errors['mname'] = 'Enter Middle Name'; 

  if (strlen($values['address']) == 0) 
  $errors['address'] = 'Enter Address'; 

  if (strlen($values['terms']) == 0) 
  $errors['terms'] = 'Please Read Terms and Agreement and Check the box.'; 

  if (!ereg('.*@.*\..{2,4}', $values['email'])) 
  $errors['email'] = 'Email address invalid'; 

  else if (strlen($values['email']) &lt; 0) 
  $errors['email'] = 'Enter Email Address'; 

  return (count($errors) == 0); 
  }</p>
<p>function DisplayForm($values, $errors) 
  { 
  ?&gt; 
  &lt;!DOCTYPE html PUBLIC &quot;-//W3C//DTD XHTML 1.0 Transitional//EN&quot; &quot;http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd&quot;&gt; 
  &lt;html xmlns=&quot;http://www.w3.org/1999/xhtml&quot;&gt; 
  &lt;head&gt; 
  &lt;meta http-equiv=&quot;Content-Type&quot; content=&quot;text/html; charset=utf-8&quot; /&gt; 
  &lt;title&gt;GIA Soap » Products » Customer Informations&lt;/title&gt; 
  &lt;link href=&quot;stylesheet/style.css&quot; rel=&quot;stylesheet&quot; type=&quot;text/css&quot; /&gt; 
  &lt;script type=&quot;text/javascript&quot; src=&quot;js_files/jquery.js&quot;&gt;&lt;/script&gt; 
  &lt;script type=&quot;text/javascript&quot; src=&quot;js_files/sliding_effect.js&quot;&gt;&lt;/script&gt; 
  &lt;script type=&quot;text/javascript&quot; src=&quot;js_files/slideshow.js&quot;&gt;&lt;/script&gt; 
  &lt;/head&gt;</p>
<p>&lt;body&gt; 
  &lt;div class=&quot;bg_top&quot;&gt; 
  &lt;div class=&quot;bg_bottom&quot;&gt; 
  &lt;div class=&quot;wrapper&quot;&gt; 
  &lt;div class=&quot;header&quot;&gt; 
  &lt;div class=&quot;logo&quot;&gt; 
  &lt;/div&gt;  
  &lt;div class=&quot;logo_text&quot;&gt; 
  &lt;div class=&quot;logo_head_text&quot;&gt;Gia Soap Making&lt;/div&gt; 
  &lt;div class=&quot;logo_sub_text&quot;&gt;Sub text here&lt;/div&gt; 
  &lt;/div&gt; 
  &lt;/div&gt; 
  &lt;div class=&quot;h_nav&quot;&gt; 
  &lt;div class=&quot;h_nav_dash&quot;&gt; 

  &lt;/div&gt; 
  &lt;/div&gt; 
  &lt;div class=&quot;container&quot;&gt; 
  &lt;div class=&quot;content_term&quot;&gt; 
  &lt;div class=&quot;content_terms&quot;&gt; 
  &lt;br /&gt; 
  &lt;h1&gt;&lt;p&gt;Customer Information&lt;/p&gt;&lt;/h1&gt;&lt;br /&gt; 
  &lt;p&gt;Please the following correctly.&lt;/p&gt; 
  &lt;div class=&quot;customer_info&quot;&gt; 

  &lt;?php 
  if (count($errors) &gt; 0) 
  echo &quot;&lt;p&gt;There were some errors in your submitted form, please correct them and try again.&lt;/p&gt;&quot;; 
  ?&gt;</p>
<p> &lt;form method=&quot;post&quot; action=&quot;&lt;?= $_SERVER['PHP_SELF'] ?&gt;&quot;&gt; 

  &lt;!-- hidden values --&gt; 

  &lt;input type=&quot;hidden&quot; value=&quot;&lt;?php echo $papaya; ?&gt;&quot; name=&quot;papaya&quot; /&gt; 
  &lt;input type=&quot;hidden&quot; value=&quot;&lt;?php echo $carrot; ?&gt;&quot; name=&quot;carrot&quot; /&gt; 
  &lt;input type=&quot;hidden&quot; value=&quot;&lt;?php echo $guava; ?&gt;&quot; name=&quot;guava&quot; /&gt; 

  &lt;label for=&quot;customer_fname&quot;&gt;First Name (&lt;i&gt;Required&lt;/i&gt;)&lt;/label&gt; 
  &lt;input type=&quot;text&quot; class=&quot;textbox&quot;  id=&quot;customer_fname&quot; name=&quot;customer_fname&quot; value=&quot;&lt;?= htmlentities($values['fname']) ?&gt;&quot; /&gt; 
  &lt;span class=&quot;error_msg&quot;&gt;&lt;?= $errors['fname'] ?&gt;&lt;/span&gt; 

  &lt;label for=&quot;customer_lname&quot;&gt;Last Name (&lt;i&gt;Required&lt;/i&gt;)&lt;/label&gt; 
  &lt;input type=&quot;text&quot; class=&quot;textbox&quot;  id=&quot;customer_fname&quot; name=&quot;customer_fname&quot; value=&quot;&lt;?= htmlentities($values['lname']) ?&gt;&quot; /&gt; 
  &lt;span class=&quot;error_msg&quot;&gt;&lt;?= $errors['lname'] ?&gt;&lt;/span&gt; 

  &lt;label for=&quot;customer_mname&quot;&gt;Middle Name (&lt;i&gt;Required&lt;/i&gt;)&lt;/label&gt; 
  &lt;input type=&quot;text&quot; class=&quot;textbox&quot;  id=&quot;customer_fname&quot; name=&quot;customer_fname&quot; value=&quot;&lt;?= htmlentities($values['mname']) ?&gt;&quot; /&gt; 
  &lt;span class=&quot;error_msg&quot;&gt;&lt;?= $errors['mname'] ?&gt;&lt;/span&gt; 

  &lt;label for=&quot;customer_add&quot;&gt;Address (&lt;i&gt;Required : Complete Address Please&lt;/i&gt;)&lt;/label&gt; 
  &lt;input type=&quot;text&quot; class=&quot;textbox&quot;  id=&quot;customer_add&quot; name=&quot;customer_add1&quot; value=&quot;&lt;?= htmlentities($values['address']) ?&gt;&quot; /&gt;&lt;br /&gt; 
  &lt;input type=&quot;text&quot; class=&quot;textbox&quot;  id=&quot;customer_add&quot; name=&quot;customer_add2&quot; /&gt;&lt;br /&gt; 
  &lt;input type=&quot;text&quot; class=&quot;textbox&quot;  id=&quot;customer_add&quot; name=&quot;customer_add3&quot; /&gt; 
  &lt;span class=&quot;error_msg&quot;&gt;&lt;?= $errors['address'] ?&gt;&lt;/span&gt; 

  &lt;label for=&quot;customer_email&quot;&gt;Email Address  (&lt;i&gt;Required&lt;/i&gt;)&lt;/label&gt; 
  &lt;input type=&quot;text&quot; class=&quot;textbox&quot;  id=&quot;customer_email&quot; name=&quot;customer_email&quot; value=&quot;&lt;?= htmlentities($values['email']) ?&gt;&quot; /&gt; 
  &lt;span class=&quot;error_msg&quot;&gt;&lt;?= $errors['email'] ?&gt;&lt;/span&gt; 

  &lt;label for=&quot;customer_phone&quot;&gt;Phone Number &lt;/label&gt; 
  &lt;input type=&quot;text&quot; class=&quot;textbox&quot;  id=&quot;customer_phone&quot; name=&quot;customer_phone&quot; /&gt; 

  &lt;label for=&quot;customer_mobile&quot;&gt;Mobile Number &lt;/label&gt; 
  &lt;input type=&quot;text&quot; class=&quot;textbox&quot;  id=&quot;customer_mobile&quot; name=&quot;customer_mobile&quot; /&gt; 

  &lt;br /&gt;&lt;br /&gt; 

  &lt;div class=&quot;terms&quot;&gt; 
  &lt;center&gt; 
  &lt;h1&gt;Terms and Agreement&lt;/h1&gt;&lt;br /&gt; 
  &lt;p&gt;Please read the following.&lt;/p&gt;&lt;br /&gt; 
  &lt;/div&gt; 
  &lt;br /&gt; 

  &lt;input type=&quot;checkbox&quot; name=&quot;terms&quot; value=&quot;&lt;?= htmlentities($values['terms']) ?&gt;&quot; /&gt; I Read the Terms and Agreement&lt;br /&gt;&lt;br /&gt; 
  &lt;span class=&quot;error_msg&quot;&gt;&lt;?= $errors['terms'] ?&gt;&lt;/span&gt; 
  &lt;input type=&quot;submit&quot; value=&quot;Send Order&quot; class=&quot;prod_subbtn&quot; /&gt; 

  &lt;/center&gt; 

  &lt;/form&gt; 
  &lt;/div&gt; 
  &lt;/div&gt; 
  &lt;/div&gt; 
  &lt;div class=&quot;clear&quot;&gt;&lt;/div&gt; 
  &lt;/div&gt; 
  &lt;?php include ('includes/footer.php'); ?&gt; 
  &lt;/div&gt; 
  &lt;/div&gt; 
  &lt;/div&gt; 
  &lt;/body&gt; 
  &lt;/html&gt;</p>
<p>&lt;?php 
  }</p>
<p>function ProcessForm($values) 
  { 

  $papaya = $_POST['papaya']; 
  $carrot = $_POST['carrot']; 
  $guava = $_POST['guava']; 
  $fname = $_POST['fname']; 
  $lname = $_POST['lname']; 
  $mname = $_POST['mname']; 
  $address = $_POST['address']; 
  }</p>
<p>if ($_SERVER['REQUEST_METHOD'] == 'POST') 
  { 
  $formValues = $_POST; 
  $formErrors = array(); 

  if (!VerifyForm($formValues, $formErrors)) 
  DisplayForm($formValues, $formErrors); 
  else 
  ProcessForm($formValues); 
  } 
  else 
  DisplayForm(null, null); 
  ?&gt;</p>
</pre>

<p>The output is: <br />
[link text]<img src="http://i218.photobucket.com/albums/cc173/watanabe123/output.jpg" alt="alt text"><a href="http://i218.photobucket.com/albums/cc173/watanabe123/output.jpg" rel="nofollow">1</a></p>

<p><br />
<strong>Problem</strong><br />
the value that I put is can be seen by users.</p>
