By jdeg on
I have a form into my custom module and at the end i have
$form_state['redirect'] = "my_node";
But for some reason don't redirect to any page but drupal_goto("my_node"); does.
This is a demo of the form:
function callme_form_submit($form, &$form_state) {
$form_state['rebuild'] = true;
$form_values = $form_state['values'];
$form_values['subject'] = variable_get('callme_email_subject', t('Call me now email'));
$form_values['body'] = variable_get('callme_email_subject', t('Call me now Body'));
$email_to = variable_get('callme_email_recipient', 'info@example.com');
global $language;
$preferred_language = $language->language;
drupal_mail(
'callme',
'send_email',
$email_to,
user_preferred_language($preferred_language),
$form_values,
variable_get('site_mail', null),
true
);
$form_state["redirect"] = "thanks";
//drupal_goto("thanks");
}
Please if somebody know will be appreciated :D
Comments
you have to apply the form
you have to apply the form redirect to the form, not the form state.
Untested, but this should work:
$form["redirect"] = "thanks";
rediect on $form does not work
I have the same problem.
$form["redirect"] does not work because $from is not passed by reference unlike $form_state and so if you apply redirect on $form it is not saved outside that function scope.
I altered $form in the argument to &$form but that also did not help!!
Resolved with a small hack!
in the file node.pages.inc, if you look node_form_submit you will find the following line:
$form_state['redirect'] = 'node/'. $node->nid;
I added one more line below above line like this and it worked!:
if($node->type == 'mynode')$form_state['redirect'] = 'myredirect' ;
It looks like for a form for a node, drupal sets $form_state['redirect'] itself without checking if it was set earlier. One way may be to make it check explictely but there may be some side effects from it.
Very interesting... The
Very interesting...
The module i'm developing is for a block not for a node, so that could be the problem?
I should have previously
I should have previously mentioned this, but you can also use the destination var to set the redirect.
So in the link to hit the form you'd have something like:
/node/3/edit?destination=/node/3
Also, I just noticed that you're trying to redirect the page in form_submit. AFAIK you have to do this in hook_form. So if you set the redirect in the actual form (not at submission) it should work as expected.
$form_state['redirect'] is
$form_state['redirect'] is rubbish, it doesn't work for me as well.
I'm using:
in my node_form_submit until there will be some proper solution.
I can't use drupal_goto(), because node could be not saved and some permission conflict, because it's redirecting immediately.
If you are using
If you are using drupal_goto() at the end if your insert function, it's not the best thing to do. Other functions are called after the insert function, and if you use drupal_goto(), you miss out on them.
Contact me to contract me for D7 -> D10/11 migrations.
unset storage
try adding this before you set $form_state['redirect']
.. in your _submit handler
Peter Lindstrom
LiquidCMS - Content Solution Experts