How to get a selected option value in your controller in codeigniter Here are steps
company.php in view
<form action="" method="POST">
<select name="company" class="form control">
<option value="1">Employee </option>
<option value="2">HR</option>
<option value="3">Student</option>
</select>
<input type="submit" name="submit" value="Post it">
</form>
or Display from database field list
$cmp_values = $this->db->query("SELECT * from company");
<select name="company" aria-controls="example1" class="form-control" required>
<option value="">Select</option>
<?php foreach($cmp_values->result_array() as $cmpdet){?>
<option value="<?=$cmpdet['com_id']?>"><?=$cmpdet['com_value']?></option>
<?php }?>
</select>
<select name="company" aria-controls="example1" class="form-control" required>
<option value="">Select</option>
<?php foreach($cmp_values->result_array() as $cmpdet){?>
<option value="<?=$cmpdet['com_id']?>"><?=$cmpdet['com_value']?></option>
<?php }?>
</select>
Then in your controller:
Company.php
<?php if ( ! defined('BASEPATH')) exit('No direct script access allowed');
class Company extends CI_Controller {
public function index() {
if( $this->input->post) {
echo $this->input->post('company');
}
$this->load->view('company');
}
}
class Company extends CI_Controller {
public function index() {
if( $this->input->post) {
echo $this->input->post('company');
}
$this->load->view('company');
}
}
No comments:
Post a Comment