Support for Drupal 7 is ending on 5 January 2025—it’s time to migrate to Drupal 10! Learn about the many benefits of Drupal 10 and find migration tools in our resource center.
Sometimes you are asked to add a second submit button above each node form.
This can be easily done with a few lines of code:
secondsubmit.info
; $Id$
name = "Second submit"
description = "Second submit button on node forms."
core = "6.x"
secondsubmit.module
// $Id$
/**
* @file
* Module definition for secondsubmit.
*/
/**
* Implement hook_form_alter().
*/
function secondsubmit_form_alter(&$form, $form_state, $form_id) {
// Add a second submit button to node forms.
if ($form['#node'] && ($form_id == $form['#node']->type . '_node_form')) {
$form['secondsubmit'] = array(
'#type' => 'submit',
'#value' => t('Save & continue'),
'#weight' => -10,
'#validate' => array('node_form_validate'),
// Use default and an additional submit handler.
'#submit' => array('node_form_submit', 'additional_node_form_submit'),
);
}
}
/**
* Implement of additional form submit
*/
function additional_node_form_submit($form, &$form_state) {
// ...
}
Comments
Modifications
If you have any problems with the code above, please feel free to ask in a comment.
But please do not modify the code above to reflect your special needs as it is meant to be a general solution and does not show a specific solution.
Permission issues?
Hey there!
I am using similar code to add a button to a form accepting PayPal. Everything works perfectly fine and as expected when I'm logged into my drupal website. As soon as I log out though, the button that previously posted and redirected to PayPal, now just redirects to the local confirmation page. Code stays exactly the same. The only difference is being logged in or not.
Have you seen this behavior before? Any idea why this is happening?
Any pointers would be very appreciated.
Cheers,
Dek