Friday 17 August 2018

Codeigniter : How to get the selected option value in controller



Get the selected option value in controller


Put this code in view:

<select name="color" id="color" class="form_input">
    <option value="Red">Red </option>
    <option value="Green">Green</option>
   <option value="Blue">Blue</option>
   <option value="Yellow">Yellow</option>
   <option value="Pink">Pink</option>
</select>

Now, add following code in controller for get selected value : 

<?php $color= $this->input->post("color"); ?>



Now, get multiple selected option values in contorller


Put this following code in view:

<select  class="default " id="color" name="color[]">
   <option value="">Select color</option>
   <?php foreach ($colors as $color) {  ?>
   <option value="<?php echo $color->color_id;?>">
   <?php echo $color->color_name;?>
   </option>
   <?php } ?>
</select>


Now, add following code in controller or model for get selected values : 

<?php $colors = $this->input->post("color"); ?>










No comments:

Post a Comment