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
    – Collins
    Sep 12, 2016 at 19:13
  • Yes this is a Custom Module Form. I'll look into entity reference fields. Thank you.
    – J.Floyd
    Sep 12, 2016 at 20:20
  • Do you mean autocomplete field?
    – Jimmy Ko
    Sep 12, 2016 at 23:27

1 Answer 1


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.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.