Monday, January 3, 2011

Cancel button on Drupal form

For few hours I have been trying to figure out of how to create cancel button on Drupal form, and I finnaly I found this way!

  $form['cancel'] = array (
    '#value' => t('Cancel'),
    '#type' => 'button',
    '#attributes' => array('onclick' => 'location.replace("'. referer_uri() .'"); this.form.reset(); return false;'),
  );

location.replace is to redirect url to the previous page, but also we need to reset the field value using this.form.reset() so it wont return an error.

No comments:

Post a Comment