Posted by Jupiter on January 27, 2009 at 10:11pm
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:
<?php
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
______________________________________________________________________________________________________
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
<?phphook_form_alter(&$form, $form_state, $form_id)
?>
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.
JLA Development - Small Business Websites
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.
<?php
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';
}
?>
JLA Development - Small Business Websites
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.