Nixak Posted July 22, 2009 Share Posted July 22, 2009 Hi, sorry but i'm still learning about coding and i'm sure someone here will know an easy answer to this This is my current php code if (MODULE_TEST_STATUS == 'true') { $this->form_action_url = 'https://website.page1.com'; } else { $this->form_action_url = 'https://website.page2.com'; } } How do you recode it if you want to add a third link? Quote Link to comment https://forums.phpfreaks.com/topic/167048-solved-help-with-simple-php-task-please/ Share on other sites More sharing options...
Hybride Posted July 22, 2009 Share Posted July 22, 2009 if (MODULE_TEST_STATUS == 'true') { $this->form_action_url = 'https://website.page1.com'; } elseif { $this->form_action_url = 'https://website.page2.com'; } else { $this->form_action_url = 'https://website.page3.com'; } } Though if you're going to do more, I sincerely recommend looking up switch/case statements. Quote Link to comment https://forums.phpfreaks.com/topic/167048-solved-help-with-simple-php-task-please/#findComment-880811 Share on other sites More sharing options...
.josh Posted July 22, 2009 Share Posted July 22, 2009 hybride...you can't just have an elseif in there without an actual condition... OP: what do you mean by "add a third link" ? That piece of code there is saying "If this constant is true, assign this string (page1.com link) to a property, otherwise (if the constant is not true), assign this other string (page2.com link) to the property. So...how is this 3rd link supposed to figure in there? What condition(s) must be met? Quote Link to comment https://forums.phpfreaks.com/topic/167048-solved-help-with-simple-php-task-please/#findComment-880813 Share on other sites More sharing options...
Nixak Posted July 22, 2009 Author Share Posted July 22, 2009 Sorry what I ment is that I am able to recode part of the script to allow me to pick 1 of three options(currently it's 1 of 2 options) so if I pick option 1 then test status is true and you get sent to website.page1.com otherwise you get sent to page 2. What I need to know is how to code the piece of code above so as if i choose option one i go to page 1, option2 go to page 2 and option 3 got to page 3. Thanks for your very quick reply guys Quote Link to comment https://forums.phpfreaks.com/topic/167048-solved-help-with-simple-php-task-please/#findComment-880823 Share on other sites More sharing options...
.josh Posted July 22, 2009 Share Posted July 22, 2009 How are you "picking" these options? From a dropdown in a form? Can you just make MOD_TEST_STATUS a string containing the link, and just assign it directly to $this->form_action_url ? Quote Link to comment https://forums.phpfreaks.com/topic/167048-solved-help-with-simple-php-task-please/#findComment-880836 Share on other sites More sharing options...
Nixak Posted July 22, 2009 Author Share Posted July 22, 2009 At the moment the script allows you to pick from 2 options via 2 buttons on a an admin page. So the admin picks weather the module is running in test mode or live mode. Test mode takes you to page 1 else live mode takes you to page 2. Here's a picture. I need to add a 3rd button/option for simulator mode that would take you to a third page. Quote Link to comment https://forums.phpfreaks.com/topic/167048-solved-help-with-simple-php-task-please/#findComment-880843 Share on other sites More sharing options...
ldougherty Posted July 22, 2009 Share Posted July 22, 2009 So right now you have one toggle that basically switches between live and test mode and you want a third option? You'd have to change it to something other than true or false because that only works on two statements, not 3. Something like this is the direction to go in. if (MODULE_TEST_STATUS == 'live') { ## LIVE MODE $this->form_action_url = 'https://website.page1.com'; } elseif (MODULE_TEST_STATUS == 'test') { ## TEST MODE $this->form_action_url = 'https://website.page2.com'; } else { ## SIMULATOR $this->form_action_url = 'https://website.page3.com'; } } And on the form itself you need to add a 3rd entry and change the values from true, false to live, test, simulator. Quote Link to comment https://forums.phpfreaks.com/topic/167048-solved-help-with-simple-php-task-please/#findComment-880849 Share on other sites More sharing options...
Nixak Posted July 23, 2009 Author Share Posted July 23, 2009 Excellent, thats done the job Thank you to all of you that helped Quote Link to comment https://forums.phpfreaks.com/topic/167048-solved-help-with-simple-php-task-please/#findComment-880863 Share on other sites More sharing options...
.josh Posted July 23, 2009 Share Posted July 23, 2009 $modes = array('live' => 'https://website.page1.com', 'test' => 'https://website.page2.com', 'sim' => 'https://website.page3.com'); $this->form_action_url = ($modes[MODULE_TEST_STATUS])? $modes[MODULE_TEST_STATUS] : 'test'; // change 'test' to whatever default you want it to be; Quote Link to comment https://forums.phpfreaks.com/topic/167048-solved-help-with-simple-php-task-please/#findComment-880865 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.