Change field input type on node edit form I'm looking to change the input field widget on my form, but still accept the same value at the end of it.

I have an integer field, and I only want them to be able to select certain integers which are relative to another field in the system. Normally I would just make an integer list field, and change the safe value to the words I want them to pick. eg:

1 | Red
2 | Blue
3 | Green


However the list is constantly growing so I couldn't manually set it. I've also tried using an Entity Reference field with an Entity Reference view for the values, but I've found that it creates an error when used in conjunction with a Field Collection field in the same node form, so I'm running out of ideas.

I've written some code to give me an array of the values, keyed by the integer number I want on a per node basis which is working, but what I want is to change the input widget from a textfield to a dropdown of my allowed values, but still accept the integer key value when it's submitted.
Try this in a custom module...

/**
 * Implements hook_form_FORM_ID_alter().
 */
function MODULE_NAME_form_YOUR_FORM_ID_alter(&amp;$form, &amp;$form_state) {    

  // Replace the next 5 lines with your logic to set the array of values
  $options = array(
    1 =&gt; 'Red',
    2 =&gt; 'Blue',
    3 =&gt; 'Green',
  );    

  $form['FORM_ELEMENT_ID']['#type'] = 'select';
  $form['FORM_ELEMENT_ID']['#options'] = $options;
}


Replace MODULE_NAME, YOUR_FORM_ID and FORM_ELEMENT_ID with your module name, form id and form element key respectively.