Check your version
This tutorial covers a topic in Drupal 7 which may or may not be the version you're using. We're keeping this tutorial online as a courtesy to users of Drupal 7, but we consider it archived.
Create autocomplete fields and menu hooks.
Goal
Add an autocomplete field that uses a query from JSON output.
Prerequisites
You will need the following knowledge and skills. If you need a review, check out the Additional resources section at the bottom of this page.
- Understand how autocomplete fields work, and can be created.
- Understand how menu hooks can return data in different formats.
Tasks
Create a menu hook as an entry point for the autocomplete function.
Create a function which runs a query to find all film reviews with a title like the one being typed in.
Use the menu hook to return the data.
Return the results of the query using the function
drupal_json_output
.
Recap
- Autocomplete fields are part of Drupal core, and can be created to perform matches using any query.
- Menu hooks can return data in a specific format by using
delivery_callback
.
Further your understanding
- Continue to the next lesson: Movie Project: Add Form Data to Custom Database Tables.
Additional resources
- API Documentation: Menu system (api.drupal.org)
- Video: Overview of the Drupal Menu System (Drupalize.Me)
- API Documentation: Form API autocomplete examples (api.drupal.org)
- API Documentation: drupal_json_output (api.drupal.org)