Drupal - How to add a custom Save & <do some action> button to Node Add/Edit form?

Got it :D

Adding

'#submit' => array('mymodule_course_form_submit'),

To the submit button worked. Like this:

$form['actions']['save_add_lesson'] = array(
  '#type' => 'submit',
  '#value' => 'Save & Create a Lesson',
  '#name' => 'op',
  '#submit' => array('mymodule_course_form_submit'),
  '#redirect' => 'node/add/lesson',
  '#weight' => 1000
);

function mymodule_course_form_submit($form, &$form_state) {
    $nid = mymodule_node_save_no_redirect($form, $form_state);  

    $form_state['redirect'] = 'node/add/lesson';
    unset($_GET['destination']);
    drupal_static_reset('drupal_get_destination');

    if($nid != -1) {
        $_SESSION['mymodule_course_nid'] = $nid;
        drupal_redirect_form($form_state);      
    } else {
        // Failed to save Course...notify user
        drupal_set_message('Failed to save Course Content', 'error');
    }
}   

Tags:

Forms