title: Display form validation errors next to each field
body: <p>I am working on a simple contact form written in php and have almost everything setup as I would like for it to be except right now, all validation errors are displaying in a div on the top of my form, and I would like to change the code below so they are displayed next to the form field that caused the error, but I am not sure how to accomplish this so I have come to the experts for some advise.</p>
  
  <p><strong>PHP Validation Routine</strong></p>
  
  <pre><code>$frm_valid = new Validate();
  
  if(isset($_POST['submit'])){
  
  $rules=array(
      array('Type'=&gt;'Required','Var'=&gt;$_POST['name'],'Msg'=&gt;'Name field is required.'),
      array('Type'=&gt;'Required','Var'=&gt;$_POST['email'],'Msg'=&gt;'Email address field is required.'),
      array('Type'=&gt;'Email','Var'=&gt;$_POST['email'],'Msg'=&gt;'Your email address format is invalid.'),
      array('Type'=&gt;'Required','Var'=&gt;$_POST['subject'],'Msg'=&gt;'Subject field is required.'),
      array('Type'=&gt;'Required','Var'=&gt;$_POST['message'],'Msg'=&gt;'Message field is required.'),
  );
  
  
  $result = $frm_valid-&gt;Valid($rules);
  
  if(is_array($result)){
      // Print validation errors (if any)
      echo('&lt;div"&gt;&lt;b&gt;The form cannot be submitted until the following errors are corrected.&lt;/b&gt;&lt;ul&gt;');
  
      foreach($result as $key=&gt;$val){
        echo '&lt;li&gt;'.$val.'&lt;/li&gt;';
      }
      echo('&lt;/ul&gt;&lt;/div&gt;&lt;br /&gt;');
    } 
    else {
      // Do something else.
    }
  }
  </code></pre>
  
  <p><strong>Forms HTML</strong></p>
  
  <pre><code>&lt;form action="&lt;? echo htmlentities($_SERVER['PHP_SELF']); ?&gt;" method="post"&gt;
      &lt;input type="text" name="name" value="" /&gt; &lt;br /&gt;
  
      &lt;input type="text" name="email" value="" /&gt;  &lt;br /&gt;
  
      &lt;input type="text" name="subject" value="" /&gt; &lt;br /&gt;
  
      &lt;textarea name="message" cols="80" rows="7"&gt;&lt;/textarea&gt; &lt;br /&gt;
  
      &lt;input type="submit" name="submit" value="Send" /&gt;
  &lt;/form&gt;
  </code></pre>