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()
?
1 Answer
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' => 'Referenced field title',
'#description' => t('Referenced field description.'),
'#type' => 'textfield',
'#autocomplete_path' => 'node_reference/autocomplete',
'#required' => TRUE, // Optional depending on your circumstance.
);
See node_reference.module line 892 for more details on parameters, etc.
-
i am using the
entity reference
module and since there wasn't a replay for a couple days, i've implemented this in a different way. didn't managed to get it to work within the form. thanks anyway for your help– rugarApr 19, 2013 at 21:35