Jump to content

[SOLVED] $_Post dont pull checkbox values?


StefanRSA

Recommended Posts

I am building dynamic fields for a form. I need a multiple value check box and I get the values from my db.

 

else if ($ftype == 'select'){
$value=explode(", ", $fval);
for($i = 0; $i < count($value); $i++){
$val2 .= '<input type="checkbox" name="'.$fname.'" value="'.$value[$i].'">'.$value[$i].'<br>';
}

 

The field display fine on my page, but when I select more than one checkbox, only one gets posted???? My post value is as follow:

$query = mysql_query("SELECT * FROM field_name WHERE sub_id = '$adsubcat'") or die(mysql_error());
while($rows = mysql_fetch_array($query)){
$ftype= $rows['field_type'];
$ftitle= $rows['field_title'];
$f_id = $rows['id'];
$fname= $rows['field_name'];
$fcomp= $rows['compulsory'];
$fval= $rows['val'];
$fhelp= $rows['help'];
$fid= $rows['help'];
///Posted field start here
$postedfield=trim($_POST[$fname]);
}

 

Can anybody please help?

Link to comment
https://forums.phpfreaks.com/topic/171601-solved-_post-dont-pull-checkbox-values/
Share on other sites

You need to have the name attribute as an array in your html name. So you have to add square brackets in the name in output when creating the form.

 

 

<input type="checkbox" name="myCheckboxes[]" value="" />
<input type="checkbox" name="myCheckboxes[]" value="" />
<input type="checkbox" name="myCheckboxes[]" value="" />

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.