Module Development

Movie Project: Create Autocomplete Fields for Drupal 7

This page is archived

We're keeping this page up as a courtesy to folks who may need to refer to old instructions. We don't plan to update this page.

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.

  1. Understand how autocomplete fields work, and can be created.
  2. 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

Additional resources

Creative Commons License

Drupal Training Resources by Damian Robinson are licensed under a Creative Commons Attribution-ShareAlike 4.0 International License. Based on a work at http://www.damianrobinson.co.uk.

Hands-On Exercises: Movie Project