form #checkbox broken

yched - July 12, 2007 - 00:35
Project:Drupal
Version:6.x-dev
Component:forms system
Category:bug report
Priority:critical
Assigned:Unassigned
Status:duplicate
Description

You currently cannot uncheck a selected checkbox - _submit handler keep receiving '1' for the value of the checkbox.
Example : try to unpublish a node using the node edit form.

Only single #checkbox seems to be affected? #checkboxes work fine (or this would have been noticed before, I guess...)

#1

yched - July 13, 2007 - 01:04

Not sure that's relevant, but $form['#post'] has no value for an unchecked checkbox.

So on those lines in _form_builder_handle_input_element (form.inc line 802) :

<?php
$edit
= $form['#post'];
foreach (
$form['#parents'] as $parent) {
 
$edit = isset($edit[$parent]) ? $edit[$parent] : NULL;
}
?>

$edit gets set to NULL, and $form['#value'] never gets set by form_type_checkbox_value, so with '#default_value' and the checkbox stays checked.

#2

yched - July 13, 2007 - 01:05

er, the end of the previous post should read :
'... so we stick to '#default_value' and the checkbox stays checked.'

#3

AjK - July 13, 2007 - 01:48
Status:active» needs review

Well, we're both looking in the same ball park (and we're both obviously working on it at the same time, shame you're not in #drupal right now).

Anyway, the attached patched fixed it for me (and it's right on the node of your observations above).

However, this patch does need Eaton or Chx to review

AttachmentSizeStatusTest resultOperations
form.inc_1.215.txt869 bytesIgnoredNoneNone

#4

eaton - July 14, 2007 - 00:07
Status:needs review» duplicate

The root of this problem is serious -- the WRONG version of this patch (http://drupal.org/node/121620) was committed to core. The last version of the patch in that issue fixes this issue as well as a couple of other bits.

 
 

Drupal is a registered trademark of Dries Buytaert.