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

wilson98’s picture

sorry, 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;
}

dpearcefl’s picture

Status: Active » Postponed (maintainer needs more info)

Does this issue exist in current D6?

dpearcefl’s picture

Status: Postponed (maintainer needs more info) » Active
qasimzee’s picture

I am still facing the same problem. Using 6.24

dpearcefl’s picture

wilson98, 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?

qasimzee’s picture

Never mind, I have resolved my issue. It was an error with Form API

Thanks

jesse.ivy’s picture

Hi,

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

Status: Active » Closed (outdated)

Automatically closed because Drupal 6 is no longer supported. If the issue verifiably applies to later versions, please reopen with details and update the version.