Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Checkbox always returns one value

i've got annoying problem with my checkbox.

Im getting name and value to checkbox from base (NAME:VALUE,NAME2:VALUE2,NAME3:VALUE3, etc). And I made code:

$count = count( $matches[0] );    
foreach($matches[0] as $match) {
$name_form = $matches[1][$i];
$form= '<tr><td class="head">Name</td><td>';
$value1 = explode(",",$values1); 
$n = count($value);
for ($y=0;$y<$n; $y++) 
{
$value2 = explode(":",$value1 [$y]); 
$form.= '<input type="checkbox" name="'.$name_form.'" value="'.$value2 [1].'"'.$selected.'>'.$value2 [0].'<br />';
}
$form.= '</td></tr>';
}

and I can't get values from this checkbox in array's. Everytime the script gives me just one, last checked value. I tried also foreach($_POST[$name_form]) as $name_form, it's just not working.

Everyone know what I can do?


1 Answers

Try adding '[]' at the end of the input's name:

$form.= '<input type="checkbox" name="input_name[]" value="'.$value2 [1].'"'.$selected.'>'.$value2 [0].'<br />';

Then access the checked values via

$checked = $_POST['input_name[]'];
like image 91
bjuice Avatar answered Jul 28 '26 04:07

bjuice



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!