开发者

get multiple values of checkbox

how can i get multiple checked box values in codeigniter with this code

<input type="checkbox" name="assign[]" value="Keyur">&nbsp;Keyur<br/>
        <input type="checkbox" name="assign[]" value="Ritesh">&nbsp;Ritesh<br/>
        <input type="checkbox" name="assign[]" value="Saurabh">&nbsp;Saurabh<br/>
        <input type="checkbox" name="a开发者_运维技巧ssign[]" value="Maulik">&nbsp;Maulik<br/>

at the controller

$data1 = $this->input->post('assign[]');

i do that but can't get values,where i make mistake????


Use this:

$this->input->post('assign');

It will be an array, the same thing as $_POST['assign'].

Example:

// This assumes we know the post key is set and is an array,
// but you should definitely check first
foreach ($this->input->post('assign') as $key => $value)
{
    echo "Index {$key}'s value is {$value}.";
}

Unfortunately, if you need to access a specific index, you'll have to assign it to a variable first or use $_POST instead of $this->input->post(). Example:

$assign = $this->input->post('assign');
echo $assign[0]; // First value
echo $_POST['assign'][0]; // First value

Update: As of PHP 5.4, you can access the index right from the function call like this:

$this->input->post('assign')[0];

Not that it's recommended or better, but just so you know it's possible.

Either way, make sure the post data and the index is set before you try to access it (if you need to do so this way).


Try this one, in your controller:

$data1 = $this->input->post('assign'); //this returns an array so use foreach to extract data

foreach( $data1 as $key => $value){

       echo $value.' '."</br>";

}

I have done this to my program and it worked.


try this:

for($i = 0; $i< count($_POST['assign']); $i++){
    echo $_POST['assign'][$i] . "<br />";
}
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜