Form generation

  1. drupal
    1. drupal6
    2. drupal7

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');

?>

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.

Funktionen & Methoden

NameBeschreibung
date_validateValidates the date type to stop dates like February 30, 2006.
drupal_build_formBuild and process a form based on a form id.
drupal_form_submitRetrieves a form using a form_id, populates it with $form_state['values'], processes it, and returns any validation errors encountered. This function is the programmatic counterpart to drupal_get_form().
drupal_get_formWrapper for drupal_build_form() for use when $form_state is not needed.
drupal_prepare_formPrepares 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_formThis function is the heart of form API. The form gets built, validated and in appropriate cases, submitted.
drupal_rebuild_formRetrieves a form, caches it and processes it with an empty $_POST.
drupal_redirect_formRedirect the user to a URL after a form has been processed.
drupal_retrieve_formRetrieves the structured array that defines a given form.
drupal_validate_formValidates user-submitted form data from the $form_state using the validate functions defined in a structured form array.
form_ahah_callbackMenu callback for AHAH callbacks through the #ahah['callback'] FAPI property.
form_builderWalk through the structured form array, adding any required properties to each element and mapping the incoming $_POST data to the proper elements. Also, execute any #process handlers attached to a specific element.
form_clean_idPrepare an HTML ID attribute string for a form item.
form_errorFlag an element as having an error.
form_execute_handlersA 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_cacheFetch a form from cache.
form_get_errorReturn the error message filed against the form with the specified name.
form_get_errorsReturn an associative array of all errors.
form_get_optionsTraverses a select element's #option array looking for any values that hold the given key. Returns an array of indexes that match.
form_options_flatten
form_pre_render_conditional_form_elementAdd form_element theming to an element if title or desription is set.
form_pre_render_fieldsetAdds members of this group as actual elements for rendering.
form_process_ahahAdd AHAH information about a form element to the page to communicate with javascript. If #ahah[path] is set on an element, this additional javascript is added to the page header to attach the AHAH behaviors. See ahah.js for more information.
form_process_checkboxes
form_process_dateRoll out a single date element.
form_process_fieldsetAdds fieldsets to the specified group or adds group members to this fieldset.
form_process_password_confirmExpand a password_confirm field into two text boxes.
form_process_radiosRoll out a single radios element to a list of radios, using the options array as index.
form_process_tableselectCreate the correct amount of checkbox or radio elements to populate the table.
form_process_text_formatAdd text format selector to text elements with the #text_format property.
form_process_vertical_tabsCreates a group formatted as vertical tabs.
form_process_weightExpand weight elements into selects.
form_select_options
form_set_cacheStore a form in the cache
form_set_errorFile an error against a form element.
form_set_valueChange submitted form values during the form processing cycle.
form_state_defaultsRetrieve default values for the $form_state array.
form_type_checkboxes_valueHelper function to determine the value for a checkboxes form element.
form_type_checkbox_valueHelper function to determine the value for a checkbox form element.
form_type_image_button_valueHelper function to determine the value for an image button form element.
form_type_password_confirm_valueHelper function to determine the value for a password_confirm form element.
form_type_select_valueHelper function to determine the value for a select form element.
form_type_textfield_valueHelper function to determine the value for a textfield form element.
form_type_token_valueHelper function to determine the value for form's token value.
map_monthHelper function for usage with drupal_map_assoc to display month names.
password_confirm_validateValidate password_confirm element.
theme_buttonTheme a form button.
theme_checkboxFormat a checkbox.
theme_checkboxesFormat a set of checkboxes.
theme_dateFormat a date selection element.
theme_fieldsetFormat a group of form items.
theme_fileFormat a file upload field.
theme_formFormat a form.
theme_form_elementReturn a themed form element.
theme_hiddenFormat a hidden form field.
theme_image_buttonTheme a form image button.
theme_markup
theme_passwordFormat a password field.
theme_radioFormat a radio button.
theme_radiosFormat a set of radio buttons.
theme_selectFormat a dropdown menu or scrolling selection box.
theme_submitTheme a form submit button.
theme_tableselectFormat a table with radio buttons or checkboxes.
theme_textareaFormat a textarea.
theme_textfieldFormat a textfield.
theme_text_format_wrapperReturn a themed text format form element.
theme_vertical_tabsMakes the element's children fieldsets be vertical tabs.
weight_valueIf no default value is set for weight select boxes, use 0.
_form_builder_handle_input_elementPopulate the #value and #name properties of input elements so they can be processed and rendered.
_form_builder_ie_cleanupIn 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_clickedHelper function to handle the sometimes-convoluted logic of button click detection.
_form_set_classSets a form element's class attribute.
_form_set_valueHelper function for form_set_value().
_form_validatePerforms 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.

includes/form.inc, line 23

Kommentare

Kommentar hinzufügen

Der Inhalt dieses Feldes wird nicht öffentlich zugänglich angezeigt.
  • Internet- und E-Mail-Adressen werden automatisch umgewandelt.
  • Zulässige HTML-Tags: <a> <em> <strong> <cite> <code> <ul> <ol> <li> <dl> <dt> <dd>
  • Zeilen und Absätze werden automatisch erzeugt.

Weitere Informationen über Formatierungsoptionen

Kommentar hinzufügen

Der Inhalt dieses Feldes wird nicht öffentlich zugänglich angezeigt.
  • Internet- und E-Mail-Adressen werden automatisch umgewandelt.
  • Zulässige HTML-Tags: <a> <em> <strong> <cite> <code> <ul> <ol> <li> <dl> <dt> <dd>
  • Zeilen und Absätze werden automatisch erzeugt.

Weitere Informationen über Formatierungsoptionen