example_element.module
Version
1.2.2.1 (checked in on 2007/07/06 at 16:17:27 by drewish)
Description
This is an example demonstrating how a module can define custom form elements.
Form elements are already familiar to anyone who uses Forms API. Examples of core form elements are 'textfield', 'checkbox' and 'fieldset'. Drupal utilizes hook_elements() to define these FAPI types, and this occurs in the core function system_elements().
Each form element has a #type value that determines how it's treated by the Form API and how it's ultimately rendered into HTML. hook_elements() allows modules to define new element types, and tell the Form API what default values they should automatically be populated with.
By implementing hook_elements in your own module, you can create custom form elements with their own properties, validation and theming.
In this example, we will define a phone number field that is expanded into several text fields for area code, phone number and extention, each of which is validated.
Functions
| Name | Description |
|---|---|
| example_element_demo | This is a simple form to demonstrate how to use the phonenumber form element we defined. |
| example_element_elements | Implementation of hook_elements(). |
| example_element_expand | Our process callback to expand the control. |
| example_element_menu | Implementation of hook_menu(). |
| example_element_validate | Our element's validation function. |
| theme_phonenumber | Theme function to format the output. |
