In the D5 Forms API, what's the best way to make a button that bypasses all the form validation and redirects to a new page?

In my custom form, I have 2 fields with '#required' => TRUE, and some custom validation as well. At the bottom of the form, I want 2 buttons:

[Submit] [Skip Details]

If the user clicks 'Skip' I want to bypass all validation and redirect to a certain Drupal path - basically this is a 'cancel' button. If the user clicks 'Skip' I want Drupal to ignore any values that may have been filled in, don't validate or process this form, just redirect to a given Drupal path. That's where I'm stuck.

Currently I have the buttons defined this way:

  $form['submit'] = array(
    '#type' => 'submit',
    '#value' => t('Submit'),
  );

  $form['skip'] = array(
    '#type' => 'submit',
    '#value' => t('Skip Details'),
  );

At the top of my validation handler I have

  if ($form_values['op'] == t('Skip Details')) {
    return;
  }

And at the top of my submit handler I have

  if ($form_values['op'] == t('Skip Details')) {
    $redirect = variable_get('signup_skip_path', '<front>');
    return $redirect;
  }

With this setup, Drupal is still running its built-in validation on the required fields, so validation is failing and my redirect also fails. So how do I make a 'Skip' button that abandons the whole form and redirects?

Comments

laken’s picture

This works:

http://drupal.org/node/100675

But it seems counter-intuitive to put the check for which button was clicked in the form-building function, rather than in the form-submit function.

Anyone know of another solution?