node_form_submit() runs after any other submit handlers that you may have created in hook_form() hook_form_alter(). And it sets the $form_values['redirect'] whether or not it exists already in the form. This means that a module cannot redirect the node/add/type form to another location.

This patch adds an isset($form_state['redirect']) conditional around the redirect declaration in node_form_submit(). This will keep any previously declared redirect from being destroyed.

CommentFileSizeAuthor
node.pages_.inc-redirect.patch720 bytesjjeff

Comments

quicksketch’s picture

Status: Needs review » Closed (works as designed)

After talking with Jjeff, we determined that the problem was that the node submission handling is no longer handled by a general #submit function on the $form variable, but instead a #submit attached to the Submit button. Placing a #submit function on the button after the node module's submit function works fine to return a different redirect path.

momper’s picture

is this fixed in the current 6.6 release?

greetings momper

sp3boy’s picture

As it took me rather a long time to understand and succeed with the suggestion in comment #1, here is some code which worked for me (eventually) in my module btomccmessage:

/**
 * Implementation of hook_form_alter
 */
function btomccmessage_form_alter(&$form, $form_state, $form_id) {
  if ($form_id == 'btomccmessage_node_form') {
    $form['buttons']['submit']['#submit'][] = '_btomccmessage_form_redirect';
  }
}

/**
 * Callback function to redirect after message node creation.
 */
function _btomccmessage_form_redirect($form, &$form_state) {
  $form_state['redirect'] = 'message';
}

I had to figure out the $form['buttons']['submit']['#submit'][] reference before Drupal would take any notice of the redirect.

I'm using D6.6 so the answer to the second comment (which you probably already know) is no.

dutchslab’s picture

thanks for the example sp3boy, it worked for me like a charm as well.
geremy

heacu’s picture

subscribing -- still not fixed in drupal core!

momper’s picture

how to put it into core?

lizhenry’s picture

Looks like this would also be useful patch to help the nodegoto module come up to Drupal 6.

sreynen’s picture

You can also force your submit handler to run after node_form_submit by adding a #validate function, and appending your submit handler to the $form_state['submit_handlers'] array. Still feels a bit messy, but the button #submit solution broke something else for me.

I'm still not clear on why node_form_submit needs to override $form_state['redirect'].