function field_attach_form


Error message

User warning: The following module is missing from the file system: theme/theme. For information about how to fix this, see the documentation page. in _drupal_trigger_error_with_delayed_logging() (line 1156 of /var/www/html/elmsln_community/
cis7 field_attach_form($entity_type, $entity, &$form, &$form_state, $langcode = NULL, $options = array())
cle7 field_attach_form($entity_type, $entity, &$form, &$form_state, $langcode = NULL, $options = array())
elmsmedia7 field_attach_form($entity_type, $entity, &$form, &$form_state, $langcode = NULL, $options = array())
icor7 field_attach_form($entity_type, $entity, &$form, &$form_state, $langcode = NULL, $options = array())
meedjum_blog7 field_attach_form($entity_type, $entity, &$form, &$form_state, $langcode = NULL, $options = array())
mooc7 field_attach_form($entity_type, $entity, &$form, &$form_state, $langcode = NULL, $options = array())

Add form elements for all fields for an entity to a form structure.

The form elements for the entity's fields are added by reference as direct children in the $form parameter. This parameter can be a full form structure (most common case for entity edit forms), or a sub-element of a larger form.

By default, submitted field values appear at the top-level of $form_state['values']. A different location within $form_state['values'] can be specified by setting the '#parents' property on the incoming $form parameter. Because of name clashes, two instances of the same field cannot appear within the same $form element, or within the same '#parents' space.

For each call to field_attach_form(), field values are processed by calling field_attach_form_validate() and field_attach_submit() on the same $form element.

Sample resulting structure in $form:

  '#parents' => The location of field values in $form_state['values'],
  '#entity_type' => The name of the entity type,
  '#bundle' => The name of the bundle,
  // One sub-array per field appearing in the entity, keyed by field name.
  // The structure of the array differs slightly depending on whether the
  // widget is 'single-value' (provides the input for one field value,
  // most common case), and will therefore be repeated as many times as
  // needed, or 'multiple-values' (one single widget allows the input of
  // several values, e.g checkboxes, select box...).
  // The sub-array is nested into a $langcode key where $langcode has the
  // same value of the $langcode parameter above.
  // The '#language' key holds the same value of $langcode and it is used
  // to access the field sub-array when $langcode is unknown.
  'field_foo' => array(
    '#tree' => TRUE,
    '#field_name' => The name of the field,
    '#language' => $langcode,
    $langcode => array(
      '#field_name' => The name of the field,
      '#language' => $langcode,
      '#field_parents' => The 'parents' space for the field in the form,
         equal to the #parents property of the $form parameter received by
      '#required' => Whether or not the field is required,
      '#title' => The label of the field instance,
      '#description' => The description text for the field instance,

      // Only for 'single' widgets:
      '#theme' => 'field_multiple_value_form',
      '#cardinality' => The field cardinality,
      // One sub-array per copy of the widget, keyed by delta.
      0 => array(
        '#entity_type' => The name of the entity type,
        '#bundle' => The name of the bundle,
        '#field_name' => The name of the field,
        '#field_parents' => The 'parents' space for the field in the form,
           equal to the #parents property of the $form parameter received by
        '#title' => The title to be displayed by the widget,
        '#default_value' => The field value for delta 0,
        '#required' => Whether the widget should be marked required,
        '#delta' => 0,
        '#columns' => The array of field columns,
        // The remaining elements in the sub-array depend on the widget.
        '#type' => The type of the widget,
      1 => array(

      // Only for multiple widgets:
      '#entity_type' => The name of the entity type,
      '#bundle' => $instance['bundle'],
      '#columns'  => array_keys($field['columns']),
      // The remaining elements in the sub-array depend on the widget.
      '#type' => The type of the widget,

Additionally, some processing data is placed in $form_state, and can be accessed by field_form_get_state() and field_form_set_state().


$entity_type: The type of $entity; e.g. 'node' or 'user'.

$entity: The entity for which to load form elements, used to initialize default form values.

$form: The form structure to fill in. This can be a full form structure, or a sub-element of a larger form. The #parents property can be set to control the location of submitted field values within $form_state['values']. If not specified, $form['#parents'] is set to an empty array, placing field values at the top-level of $form_state['values'].

$form_state: An associative array containing the current state of the form.

$langcode: The language the field values are going to be entered, if no language is provided the default site language will be used.

array $options: An associative array of additional options. See _field_invoke() for details.

See also



Related topics

22 calls to field_attach_form()
accessibility_test_add_form in sites/all/modules/ulmus/accessibility/accessibility.module
Form for saving accessibiliy test entities.
accessibility_test_edit_form in sites/all/modules/ulmus/accessibility/accessibility.module
Edit form for accessibility tests.
comment_form in modules/comment/comment.module
Generate the basic commenting form, for appending to a node or display on a separate page.
field_collection_fieldset_field_widget_form in sites/all/modules/ulmus/field_collection_fieldset/field_collection_fieldset.module
Implements hook_field_widget_form().
field_collection_field_widget_form in sites/all/modules/ulmus/field_collection/field_collection.module
Implements hook_field_widget_form().

... See full list


modules/field/, line 564
Field attach API, allowing entities (nodes, users, ...) to be 'fieldable'.


function field_attach_form($entity_type, $entity, &$form, &$form_state, $langcode = NULL, $options = array()) {
  // Validate $options since this is a new parameter added after Drupal 7 was
  // released.
  $options = is_array($options) ? $options : array();

  // Set #parents to 'top-level' by default.
  $form += array('#parents' => array());

  // If no language is provided use the default site language.
  $options['language'] = field_valid_language($langcode);
  $form += (array) _field_invoke_default('form', $entity_type, $entity, $form, $form_state, $options);

  // Add custom weight handling.
  list($id, $vid, $bundle) = entity_extract_ids($entity_type, $entity);
  $form['#pre_render'][] = '_field_extra_fields_pre_render';
  $form['#entity_type'] = $entity_type;
  $form['#bundle'] = $bundle;

  // Let other modules make changes to the form.
  // Avoid module_invoke_all() to let parameters be taken by reference.
  foreach (module_implements('field_attach_form') as $module) {
    $function = $module . '_field_attach_form';
    $function($entity_type, $entity, $form, $form_state, $langcode);



Error message

  • Warning: Cannot modify header information - headers already sent by (output started at /var/www/html/elmsln_community/ in drupal_send_headers() (line 1499 of /var/www/html/elmsln_community/
  • Error: Call to undefined function apc_delete() in DrupalAPCCache->clear() (line 289 of /var/www/html/elmsln_community/
The website encountered an unexpected error. Please try again later.