Is it possible to change the field type in a node form afterwards? 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(&amp;$form, &amp;$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 =&gt; 'Value 1',
      2 =&gt; 'Value 2',
      3 =&gt; '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!
The answer is: Yes! It is possible. All I did wrong when altering the form is that I changed the '#type' of the container instead of changing the type of the textfield itself. I had to go one level deeper:

function MYMODULE_form_alter(&amp;$form, &amp;$form_state, $form_id) {
  if ($form_id == 'MYCONTENTTYPE_node_form') {
    // dpm($form);
    $form['field_MYFIELD'][LANGUAGE_NONE][0]['value']['#type'] = 'select';
    $form['field_MYFIELD'][LANGUAGE_NONE][0]['value']['#options'] = array(
      1 =&gt; 'Value 1',
      2 =&gt; 'Value 2',
      3 =&gt; 'Value 3'
    );
    // #select doesn't need #size and #maxlength
    unset($form['field_MYFIELD'][LANGUAGE_NONE][0]['value']['#size']);
    unset($form['field_MYFIELD'][LANGUAGE_NONE][0]['value']['#maxlength']);
  }
}