J.Hof J.Hof - 1 year ago 49
PHP Question

if statement for select option value

I have a select option for departments on a html form. After the user submits the form. It emails the respective department manager. Now I have a value called $email which I want to use with the IF statement depending on what department is chosen. Eg. IF new car sales is selected then $email=newsales@gmail.com or IF used car sales is selected then $email=oldsales@gmail.com

my code:

Department:<br> <select name ="department"
<option value="ADMIN">ADMIN</option>
<option value="AFTER-SALES DIRECTOR">AFTER-SALES DIRECTOR</option>
<option value="ALPINE DEALER PRINCIPAL">ALPINE DEALER PRINCIPAL</option>
<option value="AUTO ARMOUR/AUTO ENHANCE - FITMENT CENTRE (Smash and Grab)">AUTO ARMOUR/AUTO ENHANCE - FITMENT CENTRE (Smash and Grab)</option>
<option value="BANDIT-VW">BANDIT-VW</option>
<option value="BOOKINGS VW">BOOKINGS VW</option>
<option value="DRIVEWAY/WASHBAYS">DRIVEWAY/WASHBAYS</option>
<option value="FINANCE AND INSURANCE">FINANCE AND INSURANCE</option>
<option value="IT DEPARTMENT">IT DEPARTMENT</option>
<option value="MARKETING DEPARTMENT">MARKETING DEPARTMENT</option>
<option value="MASTER CARS">MASTER CARS</option>
<option value="MAYOR OF PINETOWN">MAYOR OF PINETOWN</option>
<option value="NEW CAR PREP DEPARTMENT">NEW CAR PREP DEPARMENT</option>
<option value="NUMBER PLATES">NUMBER PLATES</option>
</select

Answer Source

Short example: I have added a submit button, when you click it the form is submitted to a Php.php page where you are going to handle if-then-else block to feed the emails.

HTML

<form action="Php.php">
    Department:<br>
    <select name ="department">
            <option value="ADMIN">ADMIN</option>
            <option value="AFTER-SALES DIRECTOR">AFTER-SALES DIRECTOR</option>
            <option value="ALPINE DEALER PRINCIPAL">ALPINE DEALER PRINCIPAL</option>
            <option value="AUTO ARMOUR/AUTO ENHANCE - FITMENT CENTRE (Smash and Grab)">AUTO ARMOUR/AUTO ENHANCE - FITMENT CENTRE (Smash and Grab)</option>
            <option value="BANDIT-VW">BANDIT-VW</option>
            <option value="BOOKINGS VW">BOOKINGS VW</option>
            <option value="DRIVEWAY/WASHBAYS">DRIVEWAY/WASHBAYS</option>
            <option value="FINANCE AND INSURANCE">FINANCE AND INSURANCE</option>
            <option value="IT DEPARTMENT">IT DEPARTMENT</option>
            <option value="MARKETING DEPARTMENT">MARKETING DEPARTMENT</option>
            <option value="MASTER CARS">MASTER CARS</option>
            <option value="MAYOR OF PINETOWN">MAYOR OF PINETOWN</option>
            <option value="NEW CAR PREP DEPARTMENT">NEW CAR PREP DEPARMENT</option> 
            <option value="NUMBER PLATES">NUMBER PLATES</option>
    </select>
    <button type="submit" name="Submit" value="Submit">Submit</button>
</form>

PHP

if ($_REQUEST['Submit']=="Submit") {
    if ($_REQUEST['department']=="ADMIN"){
        enter code here
        sendMail($email,.......);
    } else if ($_REQUEST['department']=="AFTER-SALES DIRECTOR") {
        enter code here
    }
    .
    .
    .

}

You can get the sendMail code from the internet. There are plenty of good examples out there.

Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download