title: Form validation: How to give a user specific feedback with PHP?
body: <p>I have a form with 3 input boxes, 1 radio button, 3 dropdown lists and of course a submit button.</p>
  
  <p>1 dropdown box must be an integer input &amp; 1 must be alphabetic only.</p>
  
  <p>I have currently got very basic validation functionality set up which can:</p>
  
  <p>1) Check that all the require fields have been supplied with some data.
  2) Check that one input box is ints only. 
  3) check that another is letters only.</p>
  
  <p>If any input is left out, I can output an error. What I'm trying to do is determine which
  fields were left out and give the user a more specific feedback to the right of the relevant 
  field</p>
  
  <p>This is the code so far (it's probably not the most efficient solution):</p>
  
  <pre><code>if (isset($_POST['submit'])){
              $submit = ($_POST['submit']);
  
              $title = $_POST['title'];
              $duration = $_POST['duration'];
              $director = $_POST['director'];
  
  
              /*if (isset($_POST['cert'])){
              echo "cert set: ".$_POST['cert'];
              }*/
  
  
  
              //If any of the (title, duration, director) are empty or if any of the (day, month, year) are unchanged or if the cert isn't set i.e radio button checked
              //Error
              if (empty($title) || empty($duration) || empty($director) || !isset($_POST['cert']) || ($_POST['day'] == "DD") || ($_POST['month'] == "MM") || ($_POST['year'] == "YYYY")){
  
                      echo "Error";
  
              } else {
  
                          //Check if duration entered is an integer
                          if (is_int($duration) &amp;&amp; ctype_alpha($director)) {
  
                                  $cert = $_POST['cert'];
                                  $day = $_POST['day'];
                                  $month = $_POST['month'];
                                  $year = $_POST['year'];
                                  $day = convertToTwoDigit($day);
                                  $month = convertToTwoDigit($month);
                                  $year = convertToTwoDigit($year);
  
  
                                  $date = $year."/".$month."/".$day;
  
  
                                  echo "&lt;br&gt;Title: ".$title."&lt;/br&gt;"."Duration: ".$duration."&lt;/br&gt;"."Director: ".$director."&lt;/br&gt;"."Cert: ".$cert."&lt;/br&gt;Relesed on: ".$date;
  
                                  //Add values into database: 
  
                                  if ($insert = $db-&gt;query("
                                  INSERT INTO titles (cert, filmtitle, releaseDate, filmDuration, director) VALUES ('$cert', '$title', '$date', '$duration', '$director')
                                  ")){
                                      echo "You have added a film";
                                  } else {
                                      echo "Error adding";
                                  }
                      } else {
                                  echo "director or duration error";
                      }
          }
  
  
  }
  </code></pre>
  
  <p>What is required to improve the validation to be more specific. 
  Would some sort of array work ?</p>