Form generation

Functions to enable the processing and display of HTML forms.

Drupal uses these functions to achieve consistency in its form processing and presentation, while simplifying code and reducing the amount of HTML that must be explicitly generated by modules.

The drupal_get_form() function handles retrieving and processing an HTML form for modules automatically. For example:

<?php

// Display the user registration form.
  $output = drupal_get_form('user_register_form');

?>

Forms can also be built and submitted programmatically without any user input using the drupal_form_submit() function.

For information on the format of the structured arrays used to define forms, and more detailed explanations of the Form API workflow, see the reference and the quickstart guide.

Functions

NameLocationDescription
date_validateincludes/form.incValidates the date type to stop dates like February 30, 2006.
drupal_build_formincludes/form.incBuild and process a form based on a form id.
drupal_form_submitincludes/form.incRetrieves, populates, and processes a form.
drupal_get_formincludes/form.incWrapper for drupal_build_form() for use when $form_state is not needed.
drupal_prepare_formincludes/form.incPrepares a structured form array by adding required elements, executing any hook_form_alter functions, and optionally inserting a validation token to prevent tampering.
drupal_process_formincludes/form.incProcesses a form submission.
drupal_rebuild_formincludes/form.incRetrieves a form, caches it and processes it again.
drupal_redirect_formincludes/form.incRedirects the user to a URL after a form has been processed.
drupal_retrieve_formincludes/form.incRetrieves the structured array that defines a given form.
drupal_validate_formincludes/form.incValidates user-submitted form data from the $form_state using the validate functions defined in a structured form array.
form_builderincludes/form.incWalk through the structured form array, adding any required properties to each element and mapping the incoming input data to the proper elements. Also, execute any #process handlers attached to a specific element.
form_clear_errorincludes/form.incClear all errors against all form elements made by form_set_error().
form_errorincludes/form.incFlag an element as having an error.
form_execute_handlersincludes/form.incA helper function used to execute custom validation and submission handlers for a given form. Button-specific handlers are checked first. If none exist, the function falls back to form-level handlers.
form_get_cacheincludes/form.incFetch a form from cache.
form_get_errorincludes/form.incReturn the error message filed against the form with the specified name.
form_get_errorsincludes/form.incReturn an associative array of all errors.
form_get_optionsincludes/form.incTraverses a select element's #option array looking for any values that hold the given key. Returns an array of indexes that match.
form_pre_render_conditional_form_elementincludes/form.incAdd form_element theming to an element if title or description is set.
form_pre_render_fieldsetincludes/form.incAdds members of this group as actual elements for rendering.
form_process_containerincludes/form.incProcesses a container element.
form_process_dateincludes/form.incRoll out a single date element.
form_process_fieldsetincludes/form.incAdds fieldsets to the specified group or adds group members to this fieldset.
form_process_password_confirmincludes/form.incExpand a password_confirm field into two text boxes.
form_process_radiosincludes/form.incRoll out a single radios element to a list of radios, using the options array as index.
form_process_tableselectincludes/form.incCreate the correct amount of checkbox or radio elements to populate the table.
form_process_vertical_tabsincludes/form.incCreates a group formatted as vertical tabs.
form_process_weightincludes/form.incExpand weight elements into selects.
form_select_optionsincludes/form.incConvert a select form element's options array into an HTML.
form_set_cacheincludes/form.incStore a form in the cache.
form_set_errorincludes/form.incFiles an error against a form element.
form_set_valueincludes/form.incChange submitted form values during form validation.
form_state_defaultsincludes/form.incRetrieve default values for the $form_state array.
form_state_keys_no_cacheincludes/form.incReturns an array of $form_state keys that shouldn't be cached.
form_state_values_cleanincludes/form.incRemoves internal Form API elements and buttons from submitted form values.
form_type_checkboxes_valueincludes/form.incHelper function to determine the value for a checkboxes form element.
form_type_checkbox_valueincludes/form.incHelper function to determine the value for a checkbox form element.
form_type_image_button_valueincludes/form.incHelper function to determine the value for an image button form element.
form_type_password_confirm_valueincludes/form.incHelper function to determine the value for a password_confirm form element.
form_type_select_valueincludes/form.incHelper function to determine the value for a select form element.
form_type_textfield_valueincludes/form.incHelper function to determine the value for a textfield form element.
form_type_token_valueincludes/form.incHelper function to determine the value for form's token value.
map_monthincludes/form.incHelper function for usage with drupal_map_assoc to display month names.
password_confirm_validateincludes/form.incValidate password_confirm element.
theme_buttonincludes/form.incTheme a button form element.
theme_checkboxincludes/form.incTheme a checkbox form element.
theme_checkboxesincludes/form.incTheme a set of checkbox form elements.
theme_containerincludes/form.incAdds a container for grouped items.
theme_dateincludes/form.incTheme a date selection form element.
theme_fieldsetincludes/form.incTheme a fieldset form element.
theme_fileincludes/form.incTheme a file upload form element.
theme_formincludes/form.incTheme a form.
theme_form_elementincludes/form.incTheme a form element.
theme_form_element_labelincludes/form.incTheme a form element label and required marker.
theme_form_required_markerincludes/form.incTheme the marker for required form elements.
theme_hiddenincludes/form.incTheme a hidden form element.
theme_image_buttonincludes/form.incTheme a image button form element.
theme_passwordincludes/form.incTheme a password form element.
theme_radioincludes/form.incTheme a radio button form element.
theme_radiosincludes/form.incTheme a set of radio button form elements.
theme_selectincludes/form.incTheme select form element.
theme_submitincludes/form.incTheme a submit button form element.
theme_tableselectincludes/form.incFormats a table with radio buttons or checkboxes.
theme_textareaincludes/form.incTheme a textarea form element.
theme_textfieldincludes/form.incTheme a textfield form element.
theme_vertical_tabsincludes/form.incMakes the element's children fieldsets be vertical tabs.
weight_valueincludes/form.incIf no default value is set for weight select boxes, use 0.
_form_builder_handle_input_elementincludes/form.incPopulate the #value and #name properties of input elements so they can be processed and rendered.
_form_builder_ie_cleanupincludes/form.incIn IE, if only one submit button is present, AND the enter key is used to submit the form, no form value is sent for it and our normal button detection code will never detect a match. We call this function after all other button-detection is complete...
_form_button_was_clickedincludes/form.incHelper function to handle the sometimes-convoluted logic of button click detection.
_form_set_classincludes/form.incSets a form element's class attribute.
_form_set_valueincludes/form.incHelper function for form_set_value() and _form_builder_handle_input_element().
_form_validateincludes/form.incPerforms validation on form elements. First ensures required fields are completed, #maxlength is not exceeded, and selected options were in the list of options given to the user. Then calls user-defined validators.