Jump to content

Recommended Posts

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?

Link to comment
https://forums.phpfreaks.com/topic/167048-solved-help-with-simple-php-task-please/
Share on other sites

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.

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?

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 :)

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.

 

phppic.jpg

 

I need to add a 3rd button/option for simulator mode that would take you to a third page.

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.

$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;

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.