You are here

5 April 2013

Sometimes you have to make button that skips form field validations. For an example Cancel button. This snippets shows how to skip form validation for button. Works in Drupal 7.

Source code viewer
  1. // Cancel button example.
  2.  
  3. $form['actions']['cancel'] = array(
  4. '#type' => 'submit',
  5. '#value' => t('Cancel'),
  6. '#limit_validation_errors' => array(), // This does the magic.
  7. '#submit' => array('MODULE_submit_cancel')
  8. );
  9.  
  10. function MODULE_submit_cancel(&$form, &$form_state) {
  11. drupal_goto('<front>');
  12. }
Programming Language: PHP