I've bought the gravity forms wordpress plugin and i encountered a problem with the fact that it couldn't redirect a user to a specific URL based on their input. A developer did however tell me that it has the functionality to redirect to a page and bring through a query string based on input. All i would need to do is use PHP on the page to redirect to another url based on the query string.
I've created a page /formsubmitredirect on my wordpress site and it successfully pulls in the the query string from the end of the link /formsubmitredirect?No or /formsubmitredirect?Yes based on user input.
How do i get this page to redirect based on those query string?
Thanks
The answer to your question depends on how you are grabbing the query string. Are you doing this in a page template or in a shortcode function?
The main problem if one of these is true is that if you already have loaded the header into the html before the page with your code is loaded, is that php will moan about the headers already been sent to the browser and won't do the redirect!
In my experience with wordpress, the best option would be to hook into the template_redirect action, check the query vars there and redirect before any templates are loaded by wordpress. For example:
function my_redirect(){
if(isset($_GET["yourvariable"]) && !empty($_GET["yourvariable"])){
do your redirect here with wp_redirect()
exit; //prevent wordpress continuing to load templates
}
}
add_action("template_redirect","my_redirect");
Before any output is made, change the location header:
<?
header('Location: newloc.php'); // change to your liking
The query string is in the $_GET()
array so you could do this -
if($_GET['formsubmitredirect '] == 'yes') {
header("Location: newpage");
exit();
} else {
header("Location: somewhereelse");
exit();
}
You could use
$_SERVER['QUERY_STRING']
to get the current query string and can redirect the page easily using if condition...
You could use a switch based on your GET parameter
switch ($_GET['location']) {
case 'index':
header("Location: index.php");
break;
case 'news':
header("Location: news.php");
break;
default:
header("Location: home.php");
break;
}
Now you can simply trigger this switch by using page.php?location=index