0

In my view I have the following select menu that states what type of form types are available:

<label for="add_fields_type">Type: </label>
<select name="add_fields_type" id="add_fields_type">
    <option value="input">Input</option>
    <option value="textarea">Text Area</option>
    <option value="radiobutton">Radio Button</option>
    <option value="checkbox">Check Box</option>
</select> 

In my controller I currently have the following but I am unsure how to make is so that if $_REQUEST['add_fields_type'] is = to lets say radiobutton then it will display that respective code.

Controller:

if (isset($_REQUEST['add_fields_type'])) 
        {

            echo $_REQUEST['add_fields_type'];
        }
1
  • you can use switch case for that Commented Aug 7, 2012 at 3:52

2 Answers 2

1
if (isset($_REQUEST['add_fields_type'])) {

    if ($_REQUEST['add_fields_type'] == 'input') {

            // echo stuff for input
    }
    else if ($_REQUEST['add_fields_type'] == 'textarea') {

            // echo stuff for textarea
    }
    else if ($_REQUEST['add_fields_type'] == 'radiobutton') {

            // echo stuff for radiobutton
    }
    else if ($_REQUEST['add_fields_type'] == 'checkbox') {

            // echo stuff for checkbox
    }

}
Sign up to request clarification or add additional context in comments.

Comments

1

Another way, using the switch code that swapnesh mentioned (slightly more concise than having multiple if statements and will stop when it hits the right case):

if (isset($_REQUEST['add_fields_type']))
{
    switch($_REQUEST['add_fields_type'])
    {
        case('input'):
            // echo stuff for input
            break;
        case('textarea'):
            // echo stuff for textarea
            break;
        case('radiobutton'):
            // echo stuff for radiobutton
            break;
        case('checkbox'):
            // echo stuff for checkbox
            break;
        default:
            // echo stuff if the other cases fall through
            break;
    }
}

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.