Skip to content

Instantly share code, notes, and snippets.

@koderiet
Forked from sinsunsan/cancel button.php
Created November 9, 2012 10:20
Show Gist options
  • Save koderiet/4045010 to your computer and use it in GitHub Desktop.
Save koderiet/4045010 to your computer and use it in GitHub Desktop.
Drupal 7 - Add a cancel button to drupal form
<?php
// Code copied from http://drupal.org/node/116939#comment-4906786
function MODULENAME_form_alter(&$form, $form_state, $form_id){
switch ($form_id) {
// This is our form ID.
case 'NODETYPE_node_form':
$form['buttons']['cancel'] = array (
'#type' => 'submit',
'#access' => TRUE,
'#value' => 'Cancel',
'#weight' => 60,
'#submit' => array('node_form_cancel') //This is the name of a function reproduced below
);
break;
//Continue on with other node forms, replicate for NODETYPE_ONE_node_form, for example
}
}
function node_form_cancel(){
if ($_GET['destination']){
$backurl = $_GET['destination'];
}else{
$backurl ="front"; //replace with a URL if there is not a destination parameter.
}
drupal_goto($backurl);
}
?>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment