programmatically add an existing entity reference autocomplete field in custom form I need to create a custom form and add an entity reference field to it. The field uses autocomplete with a view for entity selection. The field already exists on a node but i also need it in a custom module. Is there a way to add this field in a custom module with MYMODULE_MYFORM_form()?
If you are using the references module's node_reference field, then, in your custom form, you'll want to create a field that uses the node_reference's autocomplete, like so:

$form['referenced_field'] = array(
  '#title' =&gt; 'Referenced field title',
  '#description' =&gt; t('Referenced field description.'),
  '#type' =&gt; 'textfield',
  '#autocomplete_path' =&gt; 'node_reference/autocomplete',
  '#required' =&gt; TRUE,  // Optional depending on your circumstance.
);


See node_reference.module line 892 for more details on parameters, etc.