I'd like to overwrite the final destination after a form is submitted in the ecard module

I was hopeful in trying to do this very simple thing:


function formalter_ecard_form_form_alter(&$form, &$form_state)
{
  $form_state['redirect'] = 'process-your-donation';
}

But I'm obviously sadly mistaken :(

What's the real way to change $form_state['redirect']?

Comments

davemybes’s picture

I modified the redirect in a new hook_submit function. It looks just like your form_alter function, except that "form_alter" gets changed to "submit".
______________________________________________________________________________________________________
mybesinformatik.com - Drupal website development

______________________________________________________________________________________________________

jmlavarenne’s picture

I tried it, and it did not do the trick. I look at the API and as far as I can tell hook_submit acts on nodes when they are submitted, not forms.

jefflane’s picture

hook_form_alter doesn't take form_state by reference, so you can't change it like that

according to http://api.drupal.org/api/function/hook_form_alter
hook_form_alter(&$form, $form_state, $form_id) is the correct prototype

That being said, I also want to change $form_state from hook_form_alter, I'll let you know if I find out how to do it.

jefflane’s picture

This should work. Although, you may want to avoid using hook_form_alter if you have the ability to affect the submit callback. Hope it works for you.

function jeff_form_alter(&$form, $form_state, $form_id) 
{
     $form['#submit'][] = 'jeff_form_submit';  
}

function jeff_form_submit($form, &$form_state)
{
     $form_state['redirect'] = 'process-your-donation';
}
jmlavarenne’s picture

Thanks, I'll try this out next time. I'm not sure I understand the comment about not using hook_form_alter() but I'll look into it. I suppose you mean if I should simply want to edit the callback function directly instead of assigning a new one with the hook, depending if this is my own module or if I'm hooking into someone else's.

squarecandy’s picture

Thanks - this worked for me.