Hi,
I have an odd error that I just spent a long time trying to track down. I have a cck text field, of type checkbox. It has allowed values of:
(0|Disabled 1|Enabled)
For some reason, when comment driven builds the node form, it type casts the $form_state['values']['field_name'][0]['value'] to a boolean, instead of an integer. It occurs sometime in the form_builder function, and occurs only with the comment driven form. Any chance developers could spread some light on this?
For anyone else with this issue, my work around was to create a hook_form_alter, for the content type node form that is affected, and then saying. Adding a validation function and submit function to type cast that variable back to int.
function hook_form_alter(&$form, &$form_state, $form_id) {
if ($form_id == 'CONTENTTYPE_node_form':
array_unshift($form['#validate'], '_quick_hack');
array_unshift($form['#submit'], '_quick_hack');
}
}
function _quick_hack($form, &$form_state) {
$form_state['values']['field']['0']['value'] = (int) $form_state['values']['field']['0']['value'];
}
I'm not sure if we need if for both submit and validate, but I did just to be safe.
Comments
Comment #1
eiland commentedI think I have exactly the same problem.
It worked fnie in 6.x-1.0-alpha3 but I had issues which made me upgrade to 6.x-1.x-dev
Now I get a
My text CCK field is also a on/off checkbox.
Only... I dont get where to you put that "hook alter"? I think I slept when they explained that one, but I tried template.php and the comment_driven.module...
Comment #2
eiland commentedNever mind I switched my checkbox to represent a CCK integer field instead of text. That seems to work.