Prevent ajax submit function being called when it fails validation I have a form, that when it's submitted, should be validated, and if valid, the results of that form should then appear below the form.

This works fine without AJAX: 

function _form_validate($form, &amp;$form_state) {
  if (!is_numeric($form_state['vsalues']['zip'])) {
    form_set_error('zip', 'Zip must be number');
  }
}

function _form_submit($form, &amp;$form_state) {
    $values = $form_state['values'];
    $html = "&lt;p&gt;zip: ". $values['zip'] . "&lt;/p&gt;";
    $form_state['storage'] = $html;
    $form_state['rebuild'] = TRUE;
 }


and then this gets printed out my main form in 

  $form['output'] = array(
    '#markup' =&gt; (isset($form_state['storage']))?$form_state['storage']:'',
  );


If I make it an AJAX form, and change the submit function to:

function _form_submit($form, &amp;$form_state) {
    $values = $form_state['values'];
    $html = "&lt;p&gt;zip: ". $values['zip'] . "&lt;/p&gt;";
    $form_state['storage'] = $html;
    $form_state['rebuild'] = FALSE;
    return array("#markup" =&gt; $html);
}


It works fine apart from the fact the submit callback is triggered even when validation fails (e.g. passing a non-numeric value shows both a validation error yet also prints "zip: ").

What am I doing wrong? How can I stop the submit function being called?
Only thing you should have to put in your AJAX submit callback is this

  if (!form_get_errors()) {
    // Do your processing
  }
  else {
    // Return your form with errors.
   return $form;
  }