I would like to use the Form API to create a form that uses a textfield that references all the current nodes as an autocomplete. Is there a way to added field using the FAPI that allows a user to type the node's title or ID and the field is validated by whether the node exists.
-
Is the form a custom module form? Might be easier to use an entity reference auto complete field, and then do your own validation function to determine whether the node exists or not– CollinsCommented Sep 12, 2016 at 19:13
-
Yes this is a Custom Module Form. I'll look into entity reference fields. Thank you.– J.FloydCommented Sep 12, 2016 at 20:20
-
Do you mean autocomplete field?– Jimmy KoCommented Sep 12, 2016 at 23:27
Add a comment
|
1 Answer
If it is for a custom module, Drupal makes it quite easy to do an autocomplete field.
See a tutorial here... http://timonweb.com/posts/how-to-create-an-ajax-autocomplete-textfield-in-drupal-7/
You would then do a validation function to determine whether the entity exists, or you would only provide a list of existing entities in the first place.
If you are using the core fields, then try the entity reference module.