Hi,
I excuse my self if this has been allready asked, i just spent the three last hours searching and couldn't find an answer, so here it goes.
I need to redirect after form submit to a particular node so i pass the id to form on the URL as a $_GET['n'].
Then I use HOOK_form_FORM_ID_alter() to add the name of a custom function to the $form['actions']['submit']['#submit'] that is called after submit and it works in all forms... except those having a file upload on it.
I believe, correct me if i'm wrong, that when uploading a file either the call sequence of hooks is different or the redirections are blocked for some reason.
Here is the code example for two forms (first works the second don't):
/* FORM WITHOUT ANY FILE UPLOAD */
function mymodule_form_titre_node_form_alter(&$form, &$form_state,$form_id){
if (isset($_GET['n']) && $node = node_load($_GET['n']) )
{
$form['actions']['submit']['#submit'][] = 'appelem_form_finish_redirect';
}
}
/* FORM WITH A FILE UPLOAD */
function mymodule_form_logo_node_form_alter(&$form, &$form_state,$form_id){
if (isset($_GET['n']) && $node = node_load($_GET['n']) )
{
$form['actions']['submit']['#submit'][] = 'mymodule_form_finish_redirect';
}
}
function mymodule_form_finish_redirect($form, &$form_state) {
/* REDIRECT TO PAGE AFTER CREATING THE NODE */
if (isset($_GET['n']) && $node = node_load($_GET['n']) )
{
$form_state['redirect'] = 'node/'.$node->nid;
}
} Can you please help me to get redirections to work on forms with file uploads ?
Thanks !
Comments
Fatal error
This is what happens when submitting the form with file upload...
Fatal error: Call to undefined function mymodule_form_finish_redirect() in /www/includes/form.inc on line 1432Solution
Finnally i walked around the problem modifing the link to the form.
I used the 'destination' param on the l() function to make the redirection at the form submit.
l("My super form", "node/add/super-content-type", array('query' => array('destination' => 'node/'.$nid)))