I’ve tried to change the redirection when I submit my edit-node form, by addming the following line to my template.php file, in my theme
$form['#redirect'] = FALSE;
I’m sure the template.php file works well because I have other lines in which I change, for example, the weights of some elements. But the redirection doesn’t work.
I’ve also tried $form[‘#redirect’] = ‘anotherPage’; without success.
What am I doing wrong ? I’m following the Drupal APIs, about forms:
http://api.drupal.org/api/drupal/developer–topics–forms_api_reference.html/6#redirect
thanks
IIRC, the
$form['#redirect']entry will only be effective if no other redirection is set later on in the form processing. If you take a look atnode_form_submit(), you can see that it sets its own redirection via$form_state['redirect'] = 'node/'. $node->nid;, thus overriding the redirection you defined in the form definition earlier on.You can work around this by adding your own submit handler callback to the
$form['#submit']array (needs to be placed after the default one). Within that callback, you can change the$form_state['redirect']to your desired path.NOTE: If the
$form['#submit']array does not yet contain the default entry duringhook_form_alter(), you might need to add another indirection by adding a callback to$form['#after_build']– within that callback, you have a final chance to manipulate the form array before it gets rendered. (Well, almost final – there is still$form['#pre_render']later on 😉