Question

in view

$male=array('id'=>'2','name'=>'gen');
$female=array('id'=>'3','name'=>'gen');
echo "<label>Gender : <label>"." ".form_radio($male)."Male".form_radio($female)."Female"."<br>";

How can i get this in controller??

My Controller

public function index()
{
    $this->load->view('include/header');
    $this->load->helper('form');
    $this->load->view('data');
    $this->load->view('include/footer');
}

public function formHandler()
{
    $data = array('name'=>$_POST['name'],'age'=>$_POST['age'],'gen'=>$_POST['gen'],'a‌​dd'=>$_POST['add']);
    $this->load->library('form_validation');
    echo $data['name'];
    //echo $data['age'];
    //echo $data['add'];
}
Était-ce utile?

La solution

In order to get a value from the radio buttons, you need to assign them a value. For example,

<form action="/formHandler" method="post">
$male=array('id'=>'2','name'=>'gen', 'value'=>'m');  
$female=array('id'=>'3','name'=>'gen', 'value'=>'f');  
echo "<label>Gender : <label>"." ".form_radio($male)."Male".form_radio($female)."Female"."<br>";
<input type="submit">
</form>

Then in the controller you would call

$var = $this->input->post('gen');

Autres conseils

Using

$radio_value = $this->input->post('gen');
$radio_value = $this->input->post('gen');
Licencié sous: CC-BY-SA avec attribution
Non affilié à StackOverflow
scroll top