Support for Drupal 7 is ending on 5 January 2025—it’s time to migrate to Drupal 10! Learn about the many benefits of Drupal 10 and find migration tools in our resource center.
By jeffheaton on
I am sure this is probably a pretty easy question, but I can't seem to find the answer. I am using Drupal 6 and would like a form to go to another page when submitted. So I am using redirect. But I want to specify a query string, and my question mark gets encoded. How do I stop this?
Specifically,
$form_state['redirect'] = "purchased.html?list=1";
But this results in the following URL:
http://localhost/purchased.html%3Flist%3D1
How do I tell it to leave my question mark and equals sign alone?
Jeff
Comments
Hi Jeff, Have you tried the
Hi Jeff,
Have you tried the url() function? http://api.drupal.org/api/function/url/6
You'll probably want to use the 'query' $options.
cheers
ken
-----------------------------------------
http://www.netrift.com - Custom modules
http://ulisting.netriftsolutions.com - Drupal Real Estate Module for Drupal 6
http://drupal.org/project/friend - Social Neworking for Drupal 6
does not seem to work
I tried that. It looks the url function is just a handy function to generate a URL string. Which has a question mark in it as well. It just returns a string. So Drupal formats the question mark returned by the url function just the same as if I had written the question mark myself. There has to be a way to tell drupal to not URL encode the string you are passing it on the "redirect" option.
drupal_goto
Ah hah! I found a way. Don't use
$form_state['redirect']
Instead use drupal_goto, which has options for a query string.
this will work only if you
this will work only if you don't need to process anything after the drupal_goto call is done, that is you don't have any other submit handler after the one calling the drupal_goto
http://ericmaster.ninja
Ericmaster
drupal_goto used to change url AT VALIDATION FAILURE
Thanks Jeff! Your post, although old, lead me to a different solution. It took me many hours to discover, i looked at changing the $form["#action"],$form_state['redirect'] or doing a" hook_form_alter" but couldn't get those to work.
I needed to change the url redirected to AT VALIDATION FAILURE, not the submission redirect i.e. $form_state['redirect'].
Here is an example of code that could be used:
drupal_goto can be used to pinpoint accordions actions using url
What i should also mention here is that using drupal_goto became key for me to be able to open accordions holding different forms on the same page. Being able to set the validation failure url to documents/search?p=0 meant that the following accordion code would fire and thereby make the form concerned visible to the user on the same page being viewed which was documents/search . #mapAccordion was my selector.
use an array?
use an array?
Yup if its an array its gets
Yup, if its an array it gets passed into drupal_goto like this
call_user_func_array('drupal_goto', $goto);
.To see how your array should work just look at the docs for drupal_goto() and match your array to its arguments.
If anybody is interested here is an example taken from the docs.
http://api.drupal.org/api/drupal/includes--form.inc/function/drupal_redi...
D7
and for D6
Or
FYI to everybody talking about using drupal_goto. You should never use drupal_goto directly in a form submit function, you will be cutting off all other modules that might have added their own submit handler and that runs after your function. That is why Drupal Core provides the redirect form state option so that redirecting can happen after all form processing has completed.
This the solution!
This the solution!
Thanks a lot.
David THOMAS
http://www.smol.org
Use htaccess
I think the only way to do that properly is .htaccess with the rewriterule
Incorrect. See the post above
Incorrect. See the post above yours by naX for the method to do it.
You can use this by
You can use this by .httaccess file
first find this line of code in .htaccess file
#RewriteBase /drupal
replace it with following line of code:
RewriteBase /~yoursitename/yoursitename
Remove # from the code. Here "yoursitename" is the folder name after domain name like example.com/~yoursitename/yoursitename
form_state['redirect'] takes same args as drupal_goto
The comment above suggest the 2nd param should be an array of key-value pairs for the query string, but this does not work (in D7, at least). The Form API redirect uses url() so the 2nd argument is an options array.
i.e. the correct calling would be ('scuse short array syntax, but it's so much cooler :-D)
Rich
Artfulrobot's comment is the only correct one for D7
Skip everything else, the code in that comment worked for me.
It`s pretty handy.
It`s pretty handy.
URL function
url('some/path', array('query
url('some/path', array('query' => array('copy_txt' => 'me')));
It will work for you.