I'm using the node gallery module in Drupal 6, and I'm having some trouble modifying it to suit my needs. When the manage images form is submitted, the function node_gallery_manage_images_submit is called. At the bottom of the function is this code:

$form_state['redirect'] = 'node/'. $gid;

I need to change the URL of that to 'my_url' instead of node/123. Using the form_alter I can set $form['#action'] = 'my_url'; and when the form is submitted it goes to that page. But the module does a lot of image processing before then, so I have to use the redirect after that's all done. I also tried $form_state['#redirect'] = 'my_url'; but that did nothing. Replacing $form_state with $form does nothing either. Can anyone please help me out? I'm pretty new to Drupal forms and this is the first time I've really had to work with them. I know there has to be some way to do it, I just can't figure out how.

2 Answers 2


You should be able to achieve this by adding your own submit function to the end of the submit handler array and overriding $form_state['#redirect'] there. Example code:

function mymodule_form_node_gallery_manage_images_alter(&$form, &$form_state) {
  $form['#submit'][] = 'mymodule_node_gallery_custom_submission';

function mymodule_node_gallery_custom_submission(&$form, &$form_state) {
  $form_state['redirect'] = 'my_url';
  • Thanks a lot for your answer! I tried this, but it still is redirecting me to the same url (node/123) on form submit. Any idea why this might be happening?
    – Kyle
    Commented Jan 31, 2012 at 13:00
  • @PiontekMedia First clear caches and then check that the submit function is actually called (by adding drupal_set_message('test'); inside it for example). If things are working this far, but the redirection address is still wrong you probably have to make sure your module weights more than others that might be modifying $form_state['redirect']. You can find more information about that here.
    – Madis
    Commented Jan 31, 2012 at 16:30

As reported in other, but change a bit in submission handler like this

function mymodule_node_gallery_custom_submission(&$form, &$form_state) {
    /* for D6 */
    $form['#redirect'] = 'my_url';
    drupal_redirect_form($form, true); 
    /* for D7 
    $form_state['redirect'] = 'my_url';

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.