scenario:
1. i create a form with checkbox list for example sports and the options swimming, running, tennis, and i set the tennis for default.
2. i submit the form throught drupal_excute() and then get failed. it said sports has illegal value.
3. if i don't set default value, i still get the same error.
4. i track the bug and found that this checkboxs value is set to 1.
5. i check the source and found the problem. in function form_type_checkboxes_value() from form.inc,
$form += array('#default_value' => array());
foreach ($form['#default_value'] as $key) {
$value[$key] = 1;
}
should be replaced with:
$form += array('#default_value' => array());
foreach ($form['#default_value'] as $key => $v) {
$value[$key] = $v;
}
6. i tested it on my machine, it works fine.
Comments
Comment #1
wilson98 commentedsorry, the code above will cause bugs when submit forms from url, here's the modified version:
$form += array('#default_value' => array());
foreach ($form['#default_value'] as $key) {
$value[$key] = 1;
}
should be replaced with:
$form += array('#default_value' => array());
foreach ($form['#default_value'] as $key) {
$value[$key] = $key;
}
Comment #2
dpearcefl commentedDoes this issue exist in current D6?
Comment #3
dpearcefl commentedComment #4
qasimzee commentedI am still facing the same problem. Using 6.24
Comment #5
dpearcefl commentedwilson98, can you post your drupal_execute() code or even better, a patch?
qasimzee, are you are you using drupal_execute to create the form? If not, how are you doing it?
Comment #6
qasimzee commentedNever mind, I have resolved my issue. It was an error with Form API
Thanks
Comment #7
jesse.ivy commentedHi,
I'm terribly confused by drupal's usage of the value attribute. When writing HTML code I've typically used the value attribute for the actual value of the checkbox (i.e. an ID from the database). It seems that the drupal forms api is using the checkbox value attribute to specify the checkboxes checked state? Why?
To get to the point: Where am I supposed to store the value for the checkbox?
Thanks
~JI