1

I do this in my form submit

    $form_state['redirect']='checkout/' . $order->order_id;

but it not redirect to checkout page ( I test with another urls but it not work), I take screen shot after set redirect , enter image description here

also I get $from_state by ref in function function pre_register_node_form_submit($form, &$form_state) { , what do you think? where is the problem?

another note is when I am use drupal_goto form not saved !!!, it redirect to my page with out anything saved.

Do you suggest me declare another submit function and add it to submit array of my content type and in it set redirect?

Update

also I test below

 if ($form_id == "pre_register_node_form") {
       $form['#submit'][] = 'mysite_submit_redirect';
}

function mysite_submit_redirect(&$form, &$form_state) {
  $form_state['redirect'] = 'home';
   // ym($form_state);

}

but not redirected :(

8
  • A later function in the submit handlers list probably sets a new location. Try adjusting their order.
    – AKS
    Commented May 18, 2014 at 12:02
  • @AyeshK tnx note, I will look at it
    – Yuseferi
    Commented May 18, 2014 at 12:06
  • @AyeshK I check it ,but there is nothing else #submit (Array, 1 element) 0 (String, 29 characters ) pre_register_node_form_submit | (Callback) pre_register_node_form_submit();
    – Yuseferi
    Commented May 18, 2014 at 12:09
  • Did you check $form_state['no_redirect'] value ? If it was explicitly disallowed with a non-empty value, redirection will be skipped regardless of $form_state['redirect'] value.
    – user26231
    Commented May 18, 2014 at 13:04
  • There is not 'no_redirect` in form_state array
    – Yuseferi
    Commented May 18, 2014 at 13:05

1 Answer 1

2

If that's a node form, the problem is the node submit handler sets the redirect already in node_form_submit

If you want to redirect to checkout after a node form submit, you can do it by adding a submit handler to the $form['actions']:

/**
 * Implements hook_form_alter
 */
function MODULE_form_alter(&$form, &$form_state, $form_id) {
  if ($form_id == 'NODE_TYPE_node_form') {
    $form['actions']['submit']['#submit'][] = 'MODULE_NODE_TYPE_submit';
  }
}

/**
 * NODE_TYPE submit handler
 */
function MODULE_NODE_TYPE_submit($form, &$form_state) {
  // You don't need order_id as /checkout will route to the correct location for user
  $form_state['redirect'] = 'checkout';
}

Note: You could also do it with Rules.

5
  • May be you could use array_push to make sure your redirect is the final redirect.
    – niksmac
    Commented May 19, 2014 at 9:17
  • 1
    @Nikhil M array_push is the same as $array[] in this case. Both append the item to the array. See the note on: php.net/manual/en/function.array-push.php A benefit of array_push is that it's easier to append multiple items if necessary. Commented May 19, 2014 at 9:30
  • Yes i agree....
    – niksmac
    Commented May 19, 2014 at 9:32
  • Yes, this is good solution, tnx
    – Yuseferi
    Commented May 19, 2014 at 9:59
  • For what its worth, I found that pushing to submit array in HOOK_form_FORMID_alter also worked, for example mymodule_form_mycontenttype_node_form_alter().
    – Pete
    Commented Jul 17, 2018 at 16:21

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

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