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.
Use a form submit hook to pass information down the form API and create a node programmatically.
Goal
Create a node programmatically.
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.
- Create a form submit hook, and act upon values passed to it.
- Create a node programmatically.
Tasks
Write a "submit hook" to accept the values of the form.
For bonus points, on an existing node, you can check if the data from the external API is the same as is in the Drupal database and update the node programmatically if there are differences.
Recap
-Parameters in the form API, e.g. hook_form_validate
and hook_form_submit
are passed by reference.
- Nodes can be created programmatically and the representation of nodes when we view them is very similar in structure to when we save them.
Further your understanding
- Continue to the next lesson: Movie Project: Fetch and Attach an Image File.
Additional resources
- Video: Creating, Submitting and Validating a Simple Form (Drupalize.Me)
- API Documentation: Form generation (api.drupal.org)
- API Documentation: Node API Hooks (api.drupal.org)