function MYMODULE_form_alter($form, &$form_state, $form_id) {
    if($form_id == "zdjecie_do_projektu_node_form" ||
       $form_id == "zdjecie_ze_szkolenia_node_form" ||
       $form_id == "referencja_node_form" ||
       $form_id == "zajawka_na_stronie_glownej_node_form" ||
       $form_id == "webform_node_form") {

        $form['actions']['submit']['#submit'][] = 'MYMODULE_node_submit';

 * Custom submit function.
 * Redirect user to the site frontpage after node creation.
function MYMODULE_node_submit($form, &$form_state) {
    $form_state['redirect'] = variable_get('site_frontpage', 'node');

The source for this solution is here: http://dropbucket.org/node/245

MYMODULE is of course replaced with real module name. The problem is that both functions are reached, however redirection doesn't happen. Any ideas what am I missing here? Or what could interfere possibly with this code? I have no other custom modules and this is the only custom code. I tried with Overlay and without Overlay with no effect.

  • Is there ?destination=foo/bar in the URL when you link to the node form? – Clive Feb 10 '14 at 16:38
  • Nope, I'm adding content through admin menu. – Łukasz Zaroda Feb 10 '14 at 16:40
  • 2
    There must be something non-core interfering, try disabling the contrib modules you have installed one by one and see if you spot the culprit – Clive Feb 10 '14 at 16:48
  • Actually I disabled virtually everything and still doesn't work :| . – Łukasz Zaroda Feb 10 '14 at 21:01

If you put a die in your MYMODULE_node_submit does it stop there after the form has been submitted? If it doesn't then your submit handler is not being called and you need to debug why that isn't happening.

I just tried your code on one Drupal site I have with a good 40 or 50 modules and I could not get my additional submit handler to fire. Could not work out why.

I then put the same code on a testbed Drupal site I have with only the core modules installed and it worked straight away.

Once you've made sure that you additional submit handler is being called the you just need to put:

$form_state['redirect'] = '';

to redirect to the front page.

| improve this answer | |

if you're just redirecting to the front page after saving a specific content type, you could use rules to do that instead of a custom module.

just set up a new rule with the event of "after saving new content of type your_content_type."

then add a condition of "content is of type" with the data selector as "node" and content types value of your_content_type.

then add an action of "page redirect" and using the direct input method, use the [site:url] replacement pattern as your value.

that should redirect them to the front page after saving the new content. you can also add an event of "after updating existing content" as well.

| improve this answer | |

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.