Now, form generation engine collects the information about formelements bycalling element_info() function.This in turn callshook_element(), which might beimplemented by other modules. We can use this hook to create ourown specialized
element types, eg textbox which only takes numericinput.
Now engine know the definition of all element type, so it next itwill look for form validation function. The form validationfunction to use can be specified in any of theforms #validate,orformID_validate() or #base_validate(). #base isthe
value that you specify with the form array.
Engine will look for submit function to which the form will besubmitted. They can be specified asvalue #submit for key,orformID_submit() functionor #base_submit() function.Once it gets the submit function
for the form itcalls hook_form_alter() togive any module which wants to change the form. Basically it’s ourtime to modify someone else’s form to add or remove the inputfields and/or descriptions.
Form elements are now declared in array fashion,
with thehierarchical structure of the form elements themselves as arrayelements (which can be nested), and each form elementsproperties/attributes listed as array elements in key/valuepairs--the key being the name of the property/attribute, and thevalue being
the value of the property/attribute. For example,here's how to go about constructing a textfield formelement:
drupal_get_form
doesthe
following:
-
Starts the entire form-building process by gettingthe
$form
fromthe
builder function -
Translates the
$form['name']
itemsinto
actual form elements -
Performs any validation and "clean-up" that needs to be done, andcalls custom validation functions if declared
-
Submits the form if a submit function is declared, and the form hasbeen submitted
-
Calls any custom theming functions that have been declared
-
Returns an HTML string which contains the actual form.
The preferred method of submitting forms with the API is throughthe
use of a form submit function. This has the same namingconvention and arguments as the validation function,except _submit isappended
instead. Any forms which are submitted from a buttonof type=>
'submit'
willbe passed to their corresponding submit function
if it isavailable. This method is more secure thangrabbing $_POST['edit']
andusing
a switch statement.