| |
The secret of Forms API and hooks
This version was saved 17 years, 10 months ago
View current version Page history
Saved by PBworks
on May 12, 2006 at 8:18:34 am
- form elements are nestable (fieldset = container for other form fields)
- defined as a data strucure
- sigil indicates a named parameter
- #title, #type, #cols, #rows, etc
- #required property = "for free" validation
- data structure is handed off to drupal_get_form('form_id', $form)
- drupal_get_form outputs html-ified form for output
- Form-specific hooks
- _validate -- gets triggered by function named "(form id here)_validate" - so it's tied to the form id (validate "this form")
- fooform_validate($form_id, $form_values)
- check that your data validates the way you wanted
- _submit -- also defined based on the form_id passed to drupal_get_form()
- submit hook defines a destination
- functionality for doing stuff with data defined in the form goes in this hook
- _alter -- defined by MODULENAME_form_alter()
- applies to ALL forms
- allows you to directly modify the structure of a form before display
- add / hide elements
- change weights
- alter properties
- Theming Forms
- *everhthing* is themeable
- You can now theme forms individually
- You can also theme form /elements/ individually
- theme_formid($form) - automatic ability to customize any form's look
- use form_render() to display individual elements
- #theme_ -- allows you to customize a form or a form element
- provides ability to reuse themes for multiple forms
- General Markup
- #type => markup - insert any HTML in a form
- #prefix and #suffix - wrap something around the element
- if you don't define a #type, it defaults to markup
- Forms API Quickstart - [http://drupal.org/node/36050]
- Forms API Reference - [http://drupal.org/node/36054]
- Tips & Tricks - [http://drupal.org/node/36900]
The secret of Forms API and hooks
|
|
Tip: To turn text into a link, highlight the text, then click on a page or file from the list above.
|
|
|