I need to make a redirect after a customer added something to his cart so I write this:

function MODULE_form_alter(&$form, &$form_state, $form_id) {
  array_push($form['#submit'], '_MODULE_redirect_to_products');

function  _MODULE_redirect_to_products(&$form, &$form_state){
  global $language ;

  $form_state['redirect'] = url('prodotti', array('language' => $language));

but this code redirect me to


but I need to redirect to


according to the language obviously.

UPDATE: I'm try to use


but if I display this field before modify it I can see this

    [0] => prodotti
    [1] => Array
            [language] => stdClass Object
                    [language] => it
                    [name] => Italian
                    [native] => Italiano
                    [direction] => 0
                    [enabled] => 1
                    [plurals] => 2
                    [formula] => ($n!=1)
                    [domain] => 
                    [prefix] => it
                    [weight] => 0
                    [javascript] => a97-0F_JBbaSYaN4XQBbFbhCLCysRpSabTcDmQjB73E
                    [provider] => locale-url


    [2] => 302

but the form redirect me to 'it/testate/name' because the form 'add product' is displayed in a view so I think that the views module override the $form_state['redirect'] after me so the default redirect [and mine one..].

I think I can't use this kind of redirect.. How can I achieve this redirect correctly?

  • This starts to look like chameleon question :(
    – Mołot
    Oct 14, 2013 at 10:16
  • I know.. if I can find a way to use my code [it works redirecting to the wrong url but it redirect! ] it will be perfect.
    – Shyghar
    Oct 14, 2013 at 10:22

1 Answer 1


$form_state['redirect'] does not take full URL. It takes the same set of parameters url() does. In your case it should probably look like this:

$form_state['redirect'] = array(
  // $path
  // $options
  array('language' => $language),
  // $http_response_code
  • In the form_alter hook?
    – Shyghar
    Oct 14, 2013 at 9:08
  • @Shyghar I prefer to do it in submit handler, but if it triggers redirection when you want it, leave it be.
    – Mołot
    Oct 14, 2013 at 9:14
  • I try to add your redirect code but the form just ignore it redirecting users to the default redirect page.. This form is generating by drupal commerce.
    – Shyghar
    Oct 14, 2013 at 9:26
  • Are you sure form's submit handler is attached to form itself, not to submit button?
    – Mołot
    Oct 14, 2013 at 9:29
  • I don't know. How can I check this?
    – Shyghar
    Oct 14, 2013 at 9:40

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.