This is an example demonstrating how a module can define custom form and render elements.

Form elements are already familiar to anyone who uses Form API. They share history with render elements, which are explained in the Render Example. Examples of core form elements are 'textfield', 'checkbox' and 'fieldset'. Backdrop utilizes hook_elements() to define these FAPI types, and this occurs in system_elements().

Each form element has a #type value that determines how it is treated by the Form API and how it is ultimately rendered into HTML. hook_element_info() allows modules to define new element types, and tells the form API what default values they should automatically be populated with.

By implementing hook_element_info() in your own module, you can create custom form (or render) elements with their own properties, validation and theming.

In this example, we define a series of elements that range from trivial (a renamed textfield) to more advanced (a telephone number field with each portion separately validated).

Since each element can use arbitrary properties (like #process or #dropthis) it can be quite complicated to figure out what all the properties actually mean. This example won't undertake the exhaustive task of explaining them all, as that would probably be impossible.

File

modules/examples/form_example/form_example_elements.inc

Functions

Namesort descending Description
form_example_element_demo_form Form content for examples/form_example/element_example.
form_example_element_demo_form_submit Submit handler for form_example_element_demo_form().
form_example_phonenumber_combined_process Process callback for the combined version of the phonenumber element.
form_example_phonenumber_combined_validate Phone number validation function for the combined phonenumber.
form_example_phonenumber_combined_value Value callback for form_example_phonenumber_combined.
form_example_phonenumber_discrete_process Process callback for the discrete version of phonenumber.
form_example_phonenumber_discrete_validate Validation handler for the discrete version of the phone number.
form_type_form_example_checkbox_value Value callback for form_example_checkbox element type.
theme_form_example_checkbox Themes a custom checkbox.
theme_form_example_inline_form_element Formats child form elements as inline elements.
_form_example_element_info Utility function providing data for form_example_element_info().
_form_example_element_theme Called by form_example_theme() to provide hook_theme().