I have a CCK field (text, options widget, predefined value list) I'm using on two Node Types. On one Node Type, I'd like to allow an unlimited number of selections. On the other Node Type, I'd like to restrict the user to a single selection.
Currently, I've configured the CCK field to allow unlimited values, and am using this hook_form_alter()
code:
/*
* Implementation of hook_form_FORM_ID_alter().
*/
function custom_form_custom_node_form_alter(&$form, &$form_state) {
// http://drupal.org/node/726282
$form['#after_build'][] = 'custom_after_build';
}
function custom_after_build($form, &$form_state) {
$form['field_custom' ]['value']['#multiple'] = false;
return $form;
}
So far, so good: the field shows up as single-value on one Node Type, and multi-value on the other.
But when I click Save, the data doesn't end up in the node — I presume this is because the single-value and multi-value fields store data differently, and CCK's submit handler is expecting the data in a different format.
What do I need to do to get the single-value field data into a format CCK will understand for a multi-value field?
So far I've tried:
- implementing a
#validate
handler to alter the$form_state
array to match the$form_state
array produced by submitting a multi-value field — no effect - implementing
hook_nodeapi()
$op==='validate'
to alter the field values in the$node
object — no effect