Page 1 of 1

reading checkbox array

Posted: Sun Mar 30, 2003 5:24 am
by mzfp2
Hi

is it possible to read the values of a array of checkboxes submitted in a form?

the number of checkboxes generated is variable, and it's values as well. So i need to implement a script to read the array values as part of the the $HTTP_POST_VARS is if possible? but how?

Posted: Sun Mar 30, 2003 5:43 am
by haagen
You have to know the names of the checkboxes, because there is not a way yo tell if the value is from a checkbox or any other control. Try something like this.

Code: Select all

foreach($_POST as $key => $val){
  if(sscanf($key, "checkboxnr%d", $nbr){

    echo "Checkbox number $nbr hade the followinf value, $val";

  }
}
Note! I don't really remember the syntax of sscanf. But it think this would work.

Posted: Sun Mar 30, 2003 5:48 am
by mzfp2
phew associative arrays in play there,

ok .. is it possible therefore to give each checkbox the same name, would the code above still distinguish between the different checkboxes?

Posted: Sun Mar 30, 2003 6:37 am
by volka
I tried to explain it here: viewtopic.php?t=4396