EDIT: Answered below.

Bit of a weird one. I'd like a second Save button that saves a node but that I could target with some php.

Save Save Progress Cancel

My use-case isn't as simple as using Autosave and I don't want to start installing WorkBench or any other module for a small feature.

I could have a taxonomy field above the save where users can choose, but really, I'd prefer a second Save button for UI reasons. I could also use jQuery and have psuedo-buttons that click the appropriate term and then the save button, but I'd rather do it programmatically.



I had to do this with a validate handler instead of a submit handler. I'm not sure of the implications of that but it works.


function custom_assignment_save_form_alter(&$form, $form_state, $form_id) {
    if ($form_id == "assignment_node_form") {
        $form['secondsubmit'] = array(
        '#type' => 'submit',
        '#value' => t('Save Progress'),
        '#weight' => 100,
        '#validate' => array('node_form_validate', 'custom_assignment_save_form_validate'),
        '#submit' => array('node_form_submit'),
function custom_assignment_save_form_validate($form, &$form_state) {
    form_set_value($form['field_boolean'], array(LANGUAGE_NONE => array(0 => array('value' => 1))), $form_state);

This simply changes a hidden boolean value when the Save Progress submit button is used.


You can add a custom submit handler and then your own callback to do whatever you want.

The basic approach is:

  1. Using hook_form_alter() to target the relevant form, add another submit button that calls your callback function.
  2. Write the callback function to do whatever you want to do.

Here's an example:

function my_module_form_alter(&$form, $form_state, $form_id) {
  $form['#submit'][] = "my_module_form_submit_handler";

function my_module_form_submit_handler($form, &$form_state) {
  drupal_set_message("The form is being submitted, do some extra stuff now...");
  • Ah, that sounds like the exact start I need. I'll work on it tomorrow and report back. Thanks! – Niall Murphy Nov 25 '17 at 15:44
  • Nice, but this doesn't address the I'd like add a second save button part. – No Sssweat Nov 27 '17 at 6:21
  • @NoSssweat In step 1, I suggest using hook_form_alter() to "add another submit button." I didn't provide a code example, but I did address the question. – Patrick Kenny Nov 27 '17 at 6:24
  • I've posted an answer after working at it for a while this morning. Your pointer led me in the right direction. – Niall Murphy Nov 27 '17 at 7:04

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.