form does not respect #redirect parameter if added using hook_form_alter()

tayzlor - March 25, 2009 - 12:12
Project:Ajax
Version:6.x-1.14
Component:Code
Category:bug report
Priority:normal
Assigned:brendoncrawford
Status:active
Description

I have a situation where i'd like to redirect a node_form to a different URL after it is submitted.
The correct approach to doing this is using the form API and using a hook form alter such as -

function mymodule_form_alter(&$form, $form_state, $form_id) {
  if($form_id === 'node_form'){
    $form['#redirect'] = array('url');
  }
}

However if i do this the AJAX module does not respect my #redirect parameter in the $form array since it only looks in $form_state for the redirection.

my suggestion would be to first check the $form['#redirect'] if there is one, redirect there, else fall back on to $form_state['redirect']

does this sound sensible, or should we do this using another approach, for example have my module populate $form_state['redirect'] on a submit func before the ajax submitter is called??

if my suggestion sounds sensible, i'm attaching a patch to cover this.

AttachmentSize
ajax.module.patch346 bytes

#1

brendoncrawford - March 25, 2009 - 18:28
Assigned to:Anonymous» brendoncrawford

Taylzor,

Thanks for this feedback. You have a very good point here. I will add this fix shortly.

#2

brendoncrawford - March 26, 2009 - 03:33
Status:active» fixed

Fixed in 6.x-1.x-dev. Please allow up to 12 hours for dev package to update.

#3

brendoncrawford - March 26, 2009 - 03:54

Fixed in 6.x-1.x-dev. Please allow up to 12 hours for dev package to update.

#4

System Message - April 9, 2009 - 04:00
Status:fixed» closed

Automatically closed -- issue fixed for 2 weeks with no activity.

#5

rconstantine - June 7, 2009 - 00:06
Status:closed» active

I looked and this patch is not in the latest dev version. What gives?

#6

rconstantine - June 7, 2009 - 00:29

By the way, #redirect can accept the following and all need to be checked for:

<?php
$form
['#redirect'] = 'node';
?>


<?php
$form
['#redirect'] = array('user/login', 'destination=node');
?>


<?php
$form
['#redirect'] = FALSE;
?>

http://api.drupal.org/api/file/developer/topics/forms_api_reference.html...

Also, this should override destinations as well.

#7

jackinloadup - June 17, 2009 - 16:21

I am also having an issue with this. It has prevented me from using the ajax module. The redirections from either logintoboggan or logintoboggan are not working. Instead users are directed to the home page.

#8

jackinloadup - June 22, 2009 - 15:16

Oops. I meant the redirections from either logintoboggan or *login_destination* are not working.

#9

redijedi - June 24, 2009 - 07:46

subscribing

#10

phil88 - June 26, 2009 - 15:37
Version:6.x-1.x-dev» 6.x-1.14

subscribing

#11

Delta Bridges - June 29, 2009 - 10:22

subscribing

#12

XerraX - July 20, 2009 - 13:14

subscribing

#13

akongz - September 16, 2009 - 01:55

same here....

 
 

Drupal is a registered trademark of Dries Buytaert.