Hi--am trying to add a Cancel button to my form, but the form has required fields. I know how to specify a custom submit function for the cancel button, but how do I keep drupal_validate_form from firing???

THanks!
Doug

Comments

Anonymous’s picture

I simply used drupal_get_messages('error'); drupal_goto('somewhere/else'); for the action of the $form_state['clicked_button']['#value'] == 'Cancel'. The drupal_get_messages('error') will clear the validation error message queue. Both the drupal_get_messages('error') and the drupal_goto('somewhere/else') calls need to be in the _validate callback.

function mymodule_form_validate($form, &$form_state) {
  if ($form_state['clicked_button']['#value'] == 'Cancel') {
    drupal_get_messages('error');
    drupal_goto('node');
  }
  ... ...
}