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.
Add user data to the database from an existing form.
Goal
Save data from a form to a custom database table.
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 update user information in the database.
- Use database queries.
- Use default values in forms.
Tasks
Create a function to save the user data which has been submitted in the altered user form.
Create a function to put the data into the new table created earlier.
Create functions to retrieve the data from the form.
Set the default values of the new fields.
Recap
-
hook_user_update
can be used to manage additional functionality for a user object. - Break down functions to set and retrieve data, so they can be re-used.
Further your understanding
- Continue to the next lesson: Movie Project: Create a Render Array and Theme Functions.
Additional resources
- API Documentation: hook_user_update (api.drupal.org)
- Documentation: Database API overview (Drupal.org)
- Video: Querying the Database with Query Methods (Drupalize.Me)
- API Documentation: #default_value form attribute (api.drupal.org)