Bizarre dynamically generated checkboxes behaviour
Posted: Tue Jul 20, 2010 3:58 am
Hi all,
I'm creating dynamically a series of checkboxes in a form:
The form displays fine, but when I collect the data there are a lot of spaces added to the value... Every checkbox should return a 7 characters string that indicates a day and a timeslot (e.g. mon_mor for monday morning) but insted I receive a string that is 64 characters long and has a lot of spaces on both sides!
This is what I get with a var_dump:
[text]
array
'availability' =>
array
0 => string '
mon_mor ' (length=64)
1 => string '
thu_mor ' (length=64)
2 => string '
wed_aft ' (length=64)
[/text]
Of course I could trim the results but I'm sure there should be a more elegant way to do this... and I'd love to understand what's happening...
Thank you very much for any help,
SR
I'm creating dynamically a series of checkboxes in a form:
Code: Select all
<?php
//create checkboxes
foreach ($arrDays as $daylist => $day){
?>
<td><input type="checkbox" name="availability[]" value ="
<?php
echo "$day"._."$slot";
?>
"
<?php
//box already checked if already in database
if ($day._.$slot == 1){
echo 'checked="yes"';
}
?>
></td>
<?php
}
?>
This is what I get with a var_dump:
[text]
array
'availability' =>
array
0 => string '
mon_mor ' (length=64)
1 => string '
thu_mor ' (length=64)
2 => string '
wed_aft ' (length=64)
[/text]
Of course I could trim the results but I'm sure there should be a more elegant way to do this... and I'd love to understand what's happening...
Thank you very much for any help,
SR