The document summarizes Drupal's Forms API, which allows building forms as structured data arrays. It handles workflows and security automatically when forms are rendered to HTML. Forms are defined with functions that return arrays, and can include validation and submission functions. Behind the scenes, Drupal processes the form data, runs validation and submission functions, and renders the final output.
Report
Share
Report
Share
1 of 15
Download to read offline
More Related Content
Form API Intro
1. Forms API Inside Out
Or, How I Learned to Stop Worrying
and Love the Nested Arrays
1
2. The Olden Days
In the beginning, there was HTML
Then, there were helper functions
Each form had to reinvent workflow
Each form had to reinvent security
The Node Form made Baby Jesus cry
2
3. Drupal’s Answer: Forms API
Build forms as structured data
Make the workflow automatic
Make ‘doing the right thing’ easy
When everything is done, render to HTML
3
4. So, What’s It Look Like?
function my_form() {
$form = array();
$form['foo'] = array(
'#type' => 'textarea',
'#title' => t('Your foo'),
);
$form['submit'] = array(
'#type' => 'submit',
'#value' => t('Submit yo foo'),
);
return $form;
}
4
8. Behind the Scenes (Part 2)
Here’s that form you gave me
drupal_get_form('my_form')
$_POST has data!
my_form()
my_form_validate(...)
my_form_submit(...)
8
9. Recap, With Kittens
Call drupal_get_form(‘my_form’)
The my_form() function builds an array
Drupal sanity checks $_POST
The my_form_validate() function validates
The my_form_submit() function processes
The drupal_render() function outputs the form.
T. Keller
9
10. Here’s the Magic
Build the initial form definition
drupal_process_form()
drupal_build_form()
hook_form_alter()
_form_builder()
10
11. Here’s the Magic
_form_builder() does a lot!
Handles defaults
Weaves $_POST into the form
Builds $form_values
Inserts security tokens
11