title: Validating php form - How to show error message on the form
body: <p>I've been receiving blank submissions from my form and I know that validating ("required" validation) using javascript isn't always effective because spambots can turn off javascript.
  So I've been looking for ways to validate my php form using php.</p>
  
  <p>So after a but of research ... I found that this will work:</p>
  
  <pre><code>    if (!$_POST['name'] )
  {
  die('Please fill in your name');
  }
  </code></pre>
  
  <p>Though, this message 'Please fill in your name' shows on a different page after I've hit the submit button. Now ideally, I'd like that message to display on the page where the form is, though I'm struggling to find a way to do this. (Please excuse my lack on knowledge on php).</p>
  
  <p>Would I require Ajax? 
  I assume I would need to add a div on the form page where I want the error message to display? How would I ask php to display the error message on the form page? IE: What would I need to put in my php process form (along with the code above?).</p>
  
  <p>If you need me to post / add any more detail, please ask, as I'd appreciate your help!</p>
  
  <p>======================================================================
  UPDATE</p>
  
  <p>Here is my php process form:</p>
  
  <pre><code>&lt;?
  session_start();
  include("verification_image.class.php");
  $image = new verification_image();
  if (($image-&gt;validate_code($_POST['validate']) ? "true" : "false") == "false") {
      header('Location: http://www.domain.com/fail.htm'); 
      exit;
  }
  
  if (!$_POST['rgerger'] )
  {
  die('You did not complete all of the required fields');
  }
  
  
  if(!empty($_POST['email'])){ die('Stop Spamming'); }
  
  $to = "email@address.co.za";
  $from = $_POST['ervberster']; 
  $subject = "I Want to Advertise"; 
  $sBodyNew = '&lt;style type="text/css"&gt;
  &lt;!--
  .style {
  font-family: Arial;
  font-size: 12px;
  color: #4D241E;
  }
  body {
  background-image: url();
  background-color: #F1EAE4;
  }
  .style1 {font-size: 14px}
  --&gt;
  &lt;/style&gt;
  &lt;p&gt;&amp;nbsp;&lt;/p&gt;
  &lt;table width="420" border="0" align="center" cellpadding="0" cellspacing="5"&gt;
   &lt;tr&gt;
  &lt;td&gt;&lt;table width="100%"  border="0" cellpadding="8" cellspacing="0" bgcolor="#E7D3AF" 
  class="style"&gt;
    &lt;tr&gt;
      &lt;td colspan="2" valign="top"&gt;&lt;div align="center"&gt;&lt;strong&gt;&lt;span class="style1"&gt;I 
  Want to Advertise on AccommodationMozambique.co.za&lt;/span&gt;&lt;br&gt;
   &amp;nbsp;.................................................&lt;/strong&gt;&lt;br&gt;
   &amp;nbsp;&lt;/div&gt;&lt;/td&gt;
      &lt;/tr&gt;
    &lt;tr&gt;
      &lt;td width="32%" valign="top"&gt;&lt;div align="left"&gt;&lt;strong&gt;Date Submitted&lt;/strong&gt;
   &lt;/div&gt;&lt;/td&gt;
      &lt;td width="68%" valign="top"&gt;'. date("F j, Y, g:i a") .'&lt;/td&gt;
    &lt;/tr&gt;
    &lt;tr&gt;
      &lt;td valign="top"&gt;&lt;div align="left"&gt;&lt;strong&gt;Name&lt;/strong&gt;&lt;/div&gt;&lt;/td&gt;
      &lt;td valign="top"&gt;'.$_POST['name'].'&lt;/td&gt;
    &lt;/tr&gt;
          &lt;tr&gt;
      &lt;td valign="top"&gt;&lt;div align="left"&gt;&lt;strong&gt;Email&lt;/strong&gt;&lt;/div&gt;&lt;/td&gt;
      &lt;td valign="top"&gt;'.$_POST['ervberster'].'&lt;/td&gt;
    &lt;/tr&gt;
    &lt;tr&gt;
      &lt;td valign="top"&gt;&lt;div align="left"&gt;&lt;strong&gt;Telephone&lt;/strong&gt;&lt;/div&gt;&lt;/td&gt;
      &lt;td valign="top"&gt;'.$_POST['werergrggef'].'&lt;/td&gt;
    &lt;/tr&gt;
    &lt;tr&gt;
      &lt;td valign="top"&gt;&lt;div align="left"&gt;&lt;strong&gt;Name of Lodge&lt;/strong&gt;&lt;/div&gt;&lt;/td&gt;
      &lt;td valign="top"&gt;'.$_POST['hneyjyttyh'].'&lt;/td&gt;
    &lt;/tr&gt;
    &lt;tr&gt;
      &lt;td valign="top"&gt;&lt;div align="left"&gt;&lt;strong&gt;Town / City&lt;/strong&gt;&lt;/div&gt;&lt;/td&gt;
      &lt;td valign="top"&gt;'.$_POST['gedghethth'].'&lt;/td&gt;
    &lt;/tr&gt;
    &lt;tr&gt;
      &lt;td valign="top"&gt;&lt;div align="left"&gt;&lt;strong&gt;Enquiry&lt;/strong&gt;&lt;/div&gt;&lt;/td&gt;
      &lt;td valign="top"&gt;'.$_POST['rervberer323'].'&lt;/td&gt;
    &lt;/tr&gt;
  &lt;/table&gt;&lt;/td&gt;
  &lt;/tr&gt;
  &lt;/table&gt;
  ';            
  $headers  = "From: $from\r\n";
  $headers .= "Content-type: text/html\r\n"; 
  $success = mail($to, $subject, $sBodyNew, $headers);              
  header('Location: http://www.domain.com/success.htm');  
  ?&gt;
  </code></pre>