Latest Register Log In

+ Advanced Search

Adding Logic to Redirects

Adding Logic to Redirects
By
04/02/08 (Edited 03/10/14)

Note: This is an advanced topic for experts.

Sometimes, some of you may want to have a form redirect differently depending on the values the user has selected in it. You can apply a special message and destination url when a particular form field has a particular value, by adding the logic to your tweaks file like this:

$redirectchecks[0] = array("profile.php", "fieldname", "fieldvalue", "redirect message to display", "destination url");
$redirectchecks[1] = array("profile.php", "anotherfieldname", "anotherfieldvalue", "another redirect message to display", "anotherdestination url");
$redirectchecks[2] = array("suggest.php", "fieldname", "fieldvalue", "redirect message to display", "destination url");


Important: note that the URL being checked against is the URL of the redirect page -- not of the page with the form that was submitted. It will match any redirect page containing the first parameter you've passed, so for "suggest.php" you'll be running the check on submitting both articles and categories. There's no way to run it only on submitting articles or only on submitting categories, so hopefully your trigger field name/value combos don't conflict.

Suppose you have a custom field in your 'submit article' form called 'iwantpageb'. When it has the value 'yes' you want to send people to b.html with a "thank you for choosing page b" redirect page message in the meantime. This is what you'd use:
$redirectchecks[0] = array("suggest.php", "iwantpageb", "yes", "thank you for choosing page b", "b.html");


If you want to test for something other than equality, you can specify another operator in an optional 6th term. This can be any standard PHP operator: >, >=, <, <=, !=. For example, to redirect when something is greater than 5:
$redirectchecks[0] = array("suggest.php", "something", "5", "thank you for choosing page b", "b.html", ">");





Description How to make form submissions redirect with a special message and destination when a particular form field has a particular value.
Rating
Views 1422 views. Averaging 0 views per day.