We use cookies to improve your experience. No personal information is gathered and we don't serve ads. Cookies Policy.

ExpressionEngine Logo ExpressionEngine
Features Pricing Support Find A Developer
Partners Upgrades
Blog Add-Ons Learn
Docs Forums University
Log In or Sign Up
Log In Sign Up
ExpressionEngine Logo
Features Pro new Support Find A Developer
Partners Upgrades
Blog Add-Ons Learn
Docs Forums University Blog
  • Home
  • Forums

Using an IF Statement to find user option to then redirect to relevant webpage (noob at EE)

How Do I?

sanitizer's avatar
sanitizer
3 posts
7 years ago
sanitizer's avatar sanitizer

Hi,

Very in experienced with EE 2.4, but im experienced with PHP & HTML. I am attempting to use the following code to get variables from URL & then run an IF/IF ELSE statement:

<?php $firstname=$_GET[“firstname”]; $zipcode=$_GET[“zipcode”]; $option=$_GET[“option”];

if ($option==”Instant Medigap Prices”){ header(‘Location: 1’); } elseif ($option==”2”) { header(‘Location: location2test’); } elseif ($option==”3”){ header(‘Location: location3test’); } elseif ($option==”4”){ header(“Location: location4test”); }

?>

Obviously the above wont work in EE with php enabled. How can i change it to allow it to work? I’ve also tried using Mo Variables for aid but still unsure on implementation. i.e. how do i set a var

<?php $option = ?> {get:option} <?php ; ?>

Help & Clarification much appreciated !!

       
Robin Sowell's avatar
Robin Sowell
13,160 posts
7 years ago
Robin Sowell's avatar Robin Sowell

I think the first thing I’d do is get on the latest v2 release. 2.4 is very outdated and the docs, advice, current addons are all based on the assumption you’re running the latest release in whichever version you’re on.

It’s worth it to go ahead and update to at least 2.11.

Assuming that, I’d think Mo Variables would work- it gets you the GET variables. And based on those, do a redirect- or maybe even an html meta refresh if that works better for what you want.

Try to avoid using PHP in templates, and if you find you really need to, it’s easy to just spin up a custom plugin to do the same thing.

       
Paul Bailey's avatar
Paul Bailey
63 posts
7 years ago
Paul Bailey's avatar Paul Bailey

Stepping back a bit, if all you’re trying to do here is choose a page based on the URL, you really don’t need PHP for this. It might be worth spending some time looking into the ways that EE has of doing what you want. The basic /template_group/template method is described here:

https://docs.expressionengine.com/v2/urls/url_structure.html

The Pages module also might be useful to you. This allows you to assign an arbitrary URL to any entry:

https://docs.expressionengine.com/v2/add-ons/pages/index.html

Finally, for a more advanced (but very powerful) method, you might look at using template routes:

https://docs.expressionengine.com/v2/urls/template_routes.html

You almost never need to redirect to a page. Set things up so that EE knows which URLs belong to which content, and it’ll just happen.

       

Reply

Sign In To Reply

ExpressionEngine Home Features Pro Contact Version Support
Learn Docs University Forums
Resources Support Add-Ons Partners Blog
Privacy Terms Trademark Use License

Packet Tide owns and develops ExpressionEngine. © Packet Tide, All Rights Reserved.