By chrisdpucci on
Hey guys,
I am trying to do something that seems like it should be very simple but am running into issues.
I am wanting to use $form_state['redirect'] to send the user to a page of my module with the form values passed in the url. Again this seems like it should be really easy but I keep getting "page cannot be found" because drupal is encoding the url instead of passing the string as written.
Here is an example of my code:
function index_form_submit($form, &$form_state){
$search_string = $form_state['values']['index_search'];
$filter = $form_state['values']['filter'];
if($filter == 0){
$form_state['redirect'] = 'page1&id=' . $form_state['values']['index_search'];
} else {
$form_state['redirect'] = 'page2&id=' . $form_state['values']['index_search'];
}
I am wanting it to simply redirect to: /?q=page1&id=whatever
What I get is: /?q=page1%26id%3Dwhatever
The above comes up as page not found.
I have tried running urldecode on it but that doesn't help so I am kind of confused as to what is going on.
Any help is appreciated.
}
Comments
Nevermind. It looks like
Nevermind.
It looks like using drupal_goto works perfectly for this so no need to use form_state['redirect']
Thanks anyway, hopefully this will help someone in the future.
drupal_goto does not work for me
Hello!
I'm running drupal 6.4,
When I use drupal_goto ("mdl.php?q=ania") all I get is mdl.php%3Fq%3Dania.
How to deal with this?
Best regards, Lucas.
drupal_goto()
According to the API page for drupal_goto() (http://api.drupal.org/api/function/drupal_goto/6) the query string part of the url (the bit after the ?) goes in the second parameter of the function.
So mdl.php?q=ania becomes:
drupal_goto("mdl.php", "q=ania")Paul
A bit old, this thread, but
A bit old, this thread, but the solution is the following:
$form_state['redirect'] = array('path', 'var1=value1', 'var2=value2', etc...);The resulting redirection will look like:
?q=path&var1=value1&var2=value2...So, in your case, it would be
form_state['redirect'] = array('page1', 'id=' . $form_state['values']['index_search']);Perfect
Yes, thanks for answering, it is wise to user form_state['redirect'] rather then drupal_goto() because by using drupal_goto function all the submit functions following your submit function will not get trigger.
A better and simpler approach of submitting all the values of the form through http query is this
$form_state['redirect'] = array($_GET['q'], $form_state['values'])
This will simply pass all your POST values to GET. You could of course unset form_build_id and form_token for a nicer URL result.
Just half the truth...
...and works only with one parameter. The correct way is actually
$form_state['redirect'] = array('path', array('var1'=>'value1', 'var2'=>'value2'), 'var3');which results in
path?var1=value1&var2=value2#var3.it's the same thing.
it's the same thing. $form_state['values'] is actually an array: variable => value.
I have a problem
Help needed !!
What if you get something like this in the url
-> $form['#redirect'] = array('user/'.$id.'&quicktabs_15=6#quicktabs-15');
And Output i get as -> ?q=user/32%26quicktabs_15%3D6%23quicktabs-15
Tried the urldecode but nothing is working up.
Thanks in advance
Got the solution
Putting the above in this method works !!
$form['#redirect'] = url('user/'.$id,array('query'=>'quicktabs_15=7#quicktabs-15','absolute' => TRUE));
redirection
thanks vkareh it was very usefull
old but good
I just had to do this today and here is the solution i came up with: (d6)
1) hook_form_alter to add in a validation handler that runs before all others and extra submit handler
2) validation handler that looks at the users table login field which is 0 if a user has never logged in
3) submit handler to overwrite the redirect key
~Professional: Lullabot
~Personal: jeradbitner.com
I would
I would avoid
and use
The id properties are assign to and given that #384992: drupal_html_id does not work correctly in AJAX context with multiple forms on page is now in D7 the #id will not be totally stable for this.
$form['#redirect '] vs. $form_state['redirect']
Watch out if setting $form_state['redirect'] in a form submit handler. If $form['#redirect '] has been set, it will trump whatever you have set in $form_state['redirect'].
For confirmation of this, have a look at the code for drupal_redirect_form(), in includes/form.inc.
getting argument after redirect
I have this in one module:
$form_state['redirect'] = array('node/3',$it);
And in my node 3 it url appears as http://example.com/itc?10032
(itc is alias for node/3). My question is how can i get the value of 10032 in node/3 ?
Different in D7
In D7, the function signature of drupal_goto changed such that the second parameter is an $options array like that passed into the url() function. So to set $form_state['redirect'] in a D7 form submit function you would do something like:
Finally It work`s for me
Here is the code that work`s for me:
Form posting help required?
Hello all i m also facing a form submitting problems. This is the data which iam posting to paypal and works fine but i m not able to validate the amount. Plz any idea how to validate the amount field that it should not be null before posting? and posting should also be done right.
Redirect doesn't work.
I have a also a problem with $form_state['redirect'].
My code looks like this:
I tried several things, but nothing really works.
The form just doesn't redirect to the path I specified.
Does anyone have an idea who the redirect could work?
Try these
unset($_REQUEST['destination'], $_REQUEST['edit']['destination']);
http://drupal.org/node/942458#comment-3580862
Also $form['#redirect'] seems to override $form_state['redirect']