Support for Drupal 7 is ending on 5 January 2025—it’s time to migrate to Drupal 10! Learn about the many benefits of Drupal 10 and find migration tools in our resource center.
By jmlavarenne on
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
hook_submit
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
______________________________________________________________________________________________________
hook_submit expects a node object...
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.
hook_form_alter doesn't take
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 prototypeThat 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.
This should work. Although,
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.
Thanks, I'll try this out
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.
Thanks - this worked for me.
Thanks - this worked for me.