Drupal Forms API
This post is about the Form API of drupal6, You may find this post written in a little bit of unimpressive way, this is bcoz i am running short of time these days nonetheless i would like your suggestions and comments at any time and will try to make them happening:
Forms API
- The forms API abstracts forms into a nested array of properties and values.
- $form_values is array which holds form elements values.
- The form token (form unique id) is stored in the variables table as drupal_private_key.
- drupal_get_form() function interact with drupal form.
- hook_elements() function is used to define element type.
- hook_element() can be used to define your own element types in your module.
- element_info() hook collects all the properties for all form elements.
FORM PROPERTIES
- #validate property is used to validate the form elements.
- #base is used to apply same validator to several forms.
- #submit handles form submission. If there is no property named #submit, drupal looks for function name “formID_submit()” or failing that drupal again search for “#basevalue_submit”.
- #after_build property will call all functions of a form.
- #theme is used to set a theme to an existing form.
- #pre_render property used to call the functions just before the transformation of form from a data structure to HTML.
- #prepend, #suffix properties are used to prepend and append text to the form elements. drupal also uses these properties while rendering the form.
- #method property is used to set the form method to post. By default it is set to post, Also get method is not supported by the form API.
- #tree : Setting #tree to TRUE gives a nested array of fields with there values. While #tree is set to FALSE, we get a flattened representation of field name and values.
FLOW of form formation:
when a module contains a form code is called by drupal the form datastructure renders form into html in the following sequence:
call drupal_get_form() -> call hook_elements()['defining element types such as radio buttons, chekcboxes, textfiels'] -> call elements_info() [information about the related properties ,values and functions] -> #validate property -> #submit property
Bibliography: Apress Pro Drupal Devlopement (ycu73k6ath)
I guess i really wanted to thank you for giving us an idea regarding drupal theme it let us easy to understand the use of it.
Thanks cmsthemer