title: How to use form validation in Drupal 7
body: <p>I am trying to edit the checkout form in Drupal Commerce, to require a user to enter their email address twice.  When they submit their form, Drupal should check to see if the emails match, and call <code>form_set_error()</code> if they don't.  For now, I am just trying to attach a custom validation function to the form, which I can't get to work.  (My module is called checkout_confirm_email.  This module is only for our own use, so I didn't put much effort into the name).</p>
  
  <pre><code>function checkout_confirm_email_form_alter(&amp;$form, &amp;$form_state, $form_id) {
  if($form_id == 'commerce_checkout_form_checkout') {
      $form['#validate'][] = 'checkout_confirm_email_form_validate';
      dprint_r($form['#validate']);
      dsm("I printed");
  }
  }
  
  function checkout_confirm_email_form_validate($form, &amp;$form_state) {    
      dsm("Never prints...");
  }
  </code></pre>
  
  <p>The <code>dprint_r</code> statment outputs <code>Array ([0] =&gt; checkout_confirm_email_form_validate)</code>.  So the function is part of the form array, but the dsm statement in the validation function never prints.  </p>
  
  <p>I've actually been stuck for a while.  I've looked up examples, and I can't see what I'm doing wrong.  Anyone?</p>