1

I have overlay turned off in Drupal. When I am editing a node, I want to prevent the redirect to the node after I hit save and just stay in the back-end. (It is really a pain to have to hit "edit" and have the page re-refresh each time when one is making a little tweak. As this can be easily achieved by having to tabs open; one for the node view and one for the backend edit form)

Is there an easy way to solve this in the configuration UI?

  • you could use the rules module. Or you could set $form_state['redirect'] in your own submit function. Or you could probably add a destination url parameter to the action of the form in a form_alter. – 2pha Oct 5 '14 at 2:43
3

You can alter the form and add your own submit handler in which the user will be redirected back to the edit form:

function <MODULE>_form_alter(&$form, $form_state, $form_id) {
    if (strstr($form_id, '_node_form')) {
      $form['actions']['submit']['#submit'] = array('<MODULE>_form_submit');
    }
}
// Custom submit handler for '_node_form'.
function <MODULE>_form_submit($form, &$form_state) {
  // Call default action.
  node_form_submit($form, $form_state);
  // Redirect back to the edit page for this node.
  $form_state['redirect'] = url('node/' . $form_state['nid'] . '/edit', array(
      'absolute' => TRUE
    )
  );

  $_GET['destination'] = $form_state['redirect'];
}

You might have to tweak the above code to suit your needs.

1

There is also the Content Type Extras module that will give you an option to configure a "save and new" buttons as well as a "save and edit button". Allows also to set defaults for other things in the content type forms.

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.