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.
Make SQL queries in Drupal, make HTTP requests to external websites, and use this data to validate a form.
Goal
Query an external API to see if a movie already exists, and use this check to validate a form.
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 to check for the existence of a property on a node.
- Create a validation hook for a form.
- Use an external API to access data to use for validation.
Tasks
Create a function to check for the existence of a matching node within Drupal using the Drupal database abstraction layer. Return a boolean for whether it exists or not. If it does, notify the user that the node already exists.
Recap
- All database transactions happen via an abstraction layer.
- Making requests to external URLs is simple in Drupal 7.
Further your understanding
- Continue to the next lesson: Movie Project: Create a Node from a Custom Form.
Additional resources
- Video: Creating, Submitting and Validating a Simple Form (Drupalize.Me)
- Video: An Overview of the Database Layer in Drupal 7 (Drupalize.Me)
- Video: Querying the Database with db_select() (Drupalize.Me)
- API Documentation: Database abstraction layer (api.drupal.org)
- API Documentation: drupal_http_request (api.drupal.org)