I have an instance here where an existing textfield in a node form should be limited to enter only three possible values. I though it might be possible to alter the field to #type => 'select' and attach my '#options' as well. So I altered the form to:
function MYMODULE_form_alter(&$form, &$form_state, $form_id) {
if ($form_id == 'MYCONTENTTYPE_node_form') {
// dpm($form);
$form['field_MYFIELD']['#type'] = 'select';
$form['field_MYFIELD']['#title'] = 'Enter a value';
$form['field_MYFIELD']['#options'] = array(
1 => 'Value 1',
2 => 'Value 2',
3 => 'Value 3'
);
}
}
But when I now try to create a form like that, all I get is this error:
Fatal error: Cannot create references to/from string offsets nor overloaded objects in /Users/Shared/www/drupal.dev/includes/common.inc on line 6606
Is it even possible to change an existing field type like I want with a small custom module? Do I have to alter the submit function then as well? Please help!
$form['field_MYFIELD'][LANGUAGE_NONE][0]['value']['#type'] = 'select'];
, etc