Drupal 7 form cancel button
When creating a form it is often required to make a cancel or back button, but this provides a number og issues with form validation but fortunetly there is a way to prevent these issues.
Create your cancel or back button.
- $form['actions']['back'] = array(
- '#type' => 'submit',
- '#value' => t('Back'),
#limit_validation_errors contains an array of elements to validate on submit and since it is empty in this case nothing is validated
In order for #limit_validation_errors to work you also need to specify a submit function to call otherwise the element attribute is ignored.