How to Condition DropDown Codeigniter

We will demonstrate you to create condition a form containing a select option box field using CodeIgniter PHP framework.

In our example, we have created a select option field in form with fetched values from database using for each loop and set condition rules for fields.

<select name="outlet" class="form-control">
    <option value="">Select Outlet</option>
    <?php
    foreach ($getOutlet as $outlet)
    {
        $selected = '';
        if(!empty($this->input->get('outlet')))
        {
            if($outlet->id == $this->input->get('outlet'))
            {
                $selected = 'selected';
            }
        }
    ?>
    <option <?=$selected?> value="<?=$outlet->id?>"><?=$outlet->name?></option>
    <?php
    }
    ?>
</select>

Leave a Reply

Your email address will not be published. Required fields are marked *