0

I have a form in which I have added a cancel button which looks like this:

$form['cancel_button'] = array(
  '#type' => 'submit',
  '#value' => t('Cancel'),
  '#name' => 'cancel',
  '#access' => TRUE,
  '#submit' => array('mymodule_cancel'),
  '#limit_validation_errors' => array(),
);

This form has required elements in it as well and what is causing the problem. I thought that by having the #limit_validation_errors statement would prevent the required elements check, but that is not happening. How do I prevent the required elements from being checked?

EDIT: I found this answer on a different question Isn't it possible to have multiple buttons along with a submit button?

This would explain the behaviour I am seeing but it seems to contradict the Drupal documentation about limiting error checking. This would really screw up people who want to save a draft of a form that has required fields. I am pretty sure I have seen this done before, so there must be away around this.

1
  • If it's just a simple redirect, I'd just add #markup as a regular link.
    – AKS
    Commented Mar 15, 2013 at 13:02

1 Answer 1

-1

You can make something like this in your function validate :

function FORM_validate(&$form, &$form_state) {
if ($form_state['values']['op'] == 'cancel')
{
 ///  Do something
/// drupal_goto() for example
}
}
1
  • Never depend on this 'op'. It's translated and raw value. Use the trigger_element from $form_state.
    – AKS
    Commented Mar 15, 2013 at 13:02

Not the answer you're looking for? Browse other questions tagged or ask your own question.