? sites/default/files
? sites/default/settings.php
Index: includes/form.inc
===================================================================
RCS file: /cvs/drupal/drupal/includes/form.inc,v
retrieving revision 1.503
diff -u -p -r1.503 form.inc
--- includes/form.inc	13 Oct 2010 13:43:21 -0000	1.503
+++ includes/form.inc	15 Oct 2010 06:02:05 -0000
@@ -1698,6 +1698,13 @@ function form_builder($form_id, &$elemen
     $element['#after_build_done'] = TRUE;
   }
 
+  // Allow #limit_validation_errors of triggering element of a form
+  // to be altered in #after_build callbacks. This is needed in cases when
+  // actual position of submit button is unknown.
+  if (isset($form_state['triggering_element']) && isset($element['#name']) && ($form_state['triggering_element']['#name'] == $element['#name']) && isset($element['#limit_validation_errors'])) {
+    $form_state['triggering_element']['#limit_validation_errors'] = $element['#limit_validation_errors'];
+  }
+
   // If there is a file element, we need to flip a flag so later the
   // form encoding can be set.
   if (isset($element['#type']) && $element['#type'] == 'file') {
Index: modules/field/field.attach.inc
===================================================================
RCS file: /cvs/drupal/drupal/modules/field/field.attach.inc,v
retrieving revision 1.96
diff -u -p -r1.96 field.attach.inc
--- modules/field/field.attach.inc	3 Oct 2010 01:15:33 -0000	1.96
+++ modules/field/field.attach.inc	15 Oct 2010 06:02:06 -0000
@@ -531,14 +531,23 @@ function _field_invoke_get_instances($en
  * @param $langcode
  *   The language the field values are going to be entered, if no language
  *   is provided the default site language will be used.
+ * @param $namespace
+ *   The namespace which can be used to prevent field name collisions in
+ *   $form_state['field']. If provided field information will be
+ *   stored in $form_state['field'][$namespace].
  * @return
  *   The form elements are added by reference at the top level of the $form
  *   parameter. Processing information is added by reference in
  *   $form_state['field'].
  */
-function field_attach_form($entity_type, $entity, &$form, &$form_state, $langcode = NULL) {
+function field_attach_form($entity_type, $entity, &$form, &$form_state, $langcode = NULL, $namespace = 'default') {
   // If no language is provided use the default site language.
   $options = array('language' => field_valid_language($langcode));
+
+  // Set namespace for fields. Using non-empty default value for namespace
+  // allows to eliminate 'if isset()' check and simplifies the code.
+  $form['#namespace'] = $namespace;
+
   $form += (array) _field_invoke_default('form', $entity_type, $entity, $form, $form_state, $options);
 
   // Add custom weight handling.
@@ -787,6 +796,7 @@ function field_attach_validate($entity_t
  *   An associative array containing the current state of the form.
  */
 function field_attach_form_validate($entity_type, $entity, $form, &$form_state) {
+  $namespace = $form['#namespace'];
   // Extract field values from submitted values.
   _field_invoke_default('extract_form_values', $entity_type, $entity, $form, $form_state);
 
@@ -799,7 +809,7 @@ function field_attach_form_validate($ent
     // flagging.
     foreach ($e->errors as $field_name => $field_errors) {
       foreach ($field_errors as $langcode => $language_errors) {
-        $form_state['field'][$field_name][$langcode]['errors'] = $language_errors;
+        $form_state['field'][$namespace][$field_name][$langcode]['errors'] = $language_errors;
       }
     }
     _field_invoke_default('form_errors', $entity_type, $entity, $form, $form_state);
Index: modules/field/field.default.inc
===================================================================
RCS file: /cvs/drupal/drupal/modules/field/field.default.inc,v
retrieving revision 1.39
diff -u -p -r1.39 field.default.inc
--- modules/field/field.default.inc	4 Aug 2010 06:55:35 -0000	1.39
+++ modules/field/field.default.inc	15 Oct 2010 06:02:06 -0000
@@ -12,12 +12,17 @@
  */
 
 function field_default_extract_form_values($entity_type, $entity, $field, $instance, $langcode, &$items, $form, &$form_state) {
+  $namespace = isset($form['#namespace']) ? $form['#namespace'] : 'default';
   $field_name = $field['field_name'];
-
-  if (isset($form_state['values'][$field_name][$langcode])) {
-    $items = $form_state['values'][$field_name][$langcode];
-    // Remove the 'value' of the 'add more' button.
-    unset($items['add_more']);
+  if (isset($form_state['field'][$namespace][$field_name][$langcode]['array_parents'])) {
+    $parents = $form_state['field'][$namespace][$field_name][$langcode]['array_parents'];
+    $values = drupal_array_get_nested_value($form_state['values'], $parents);
+
+    if (is_array($values)) {
+      $items = $values;
+      // Remove the 'value' of the 'add more' button.
+      unset($items['add_more']);
+    }
   }
 }
 
Index: modules/field/field.form.inc
===================================================================
RCS file: /cvs/drupal/drupal/modules/field/field.form.inc,v
retrieving revision 1.50
diff -u -p -r1.50 field.form.inc
--- modules/field/field.form.inc	17 Jun 2010 13:44:45 -0000	1.50
+++ modules/field/field.form.inc	15 Oct 2010 06:02:09 -0000
@@ -17,6 +17,7 @@ function field_default_form($entity_type
   }
 
   $addition = array();
+  $namespace = isset($form['#namespace']) ? $form['#namespace'] : 'default';
   $field_name = $field['field_name'];
   $addition[$field_name] = array();
 
@@ -71,7 +72,7 @@ function field_default_form($entity_type
 
   if ($elements) {
     // Store field information in $form_state.
-    $form_state['field'][$field_name][$langcode] = array(
+    $form_state['field'][$namespace][$field_name][$langcode] = array(
       'field' => $field,
       'instance' => $instance,
       // This entry will be populated at form build time.
@@ -99,6 +100,7 @@ function field_default_form($entity_type
   // the form is built, so that we catch changes in the form structure performed
   // in alter() hooks.
   $elements['#after_build'][] = 'field_form_element_after_build';
+  $elements['#namespace'] = $namespace;
   $elements['#field_name'] = $field_name;
   $elements['#language'] = $langcode;
 
@@ -122,15 +124,17 @@ function field_default_form($entity_type
  * - drag-n-drop value reordering
  */
 function field_multiple_value_form($field, $instance, $langcode, $items, &$form, &$form_state) {
+  $namespace = $form['#namespace'];
   $field_name = $field['field_name'];
 
   // Determine the number of widgets to display.
   switch ($field['cardinality']) {
     case FIELD_CARDINALITY_UNLIMITED:
       $filled_items = _field_filter_items($field, $items);
-      $current_item_count = isset($form_state['field_item_count'][$field_name])
-                            ? $form_state['field_item_count'][$field_name]
+      $current_item_count = isset($form_state['field_item_count'][$namespace][$field_name])
+                            ? $form_state['field_item_count'][$namespace][$field_name]
                             : count($items);
+
       // We always want at least one empty icon for the user to fill in.
       $max = ($current_item_count > count($filled_items))
               ? $current_item_count - 1
@@ -144,7 +148,7 @@ function field_multiple_value_form($fiel
 
   $title = check_plain(t($instance['label']));
   $description = field_filter_xss(t($instance['description']));
-  $wrapper_id = drupal_html_id($field_name . '-add-more-wrapper');
+  $wrapper_id = drupal_html_id($namespace . '-' . $field_name . '-add-more-wrapper');
   $field_elements = array();
 
   $function = $instance['widget']['module'] . '_field_widget_form';
@@ -198,10 +202,11 @@ function field_multiple_value_form($fiel
       if ($field['cardinality'] == FIELD_CARDINALITY_UNLIMITED && empty($form_state['programmed'])) {
         $field_elements['add_more'] = array(
           '#type' => 'submit',
-          '#name' => $field_name . '_add_more',
+          '#name' => $namespace . '_' . $field_name . '_add_more',
           '#value' => t('Add another item'),
           '#attributes' => array('class' => array('field-add-more-submit')),
-          '#limit_validation_errors' => array(array($field_name, $langcode)),
+          // This will be updated on after_build
+          '#limit_validation_errors' => array(),
           '#submit' => array('field_add_more_submit'),
           '#ajax' => array(
             'callback' => 'field_add_more_js',
@@ -210,8 +215,11 @@ function field_multiple_value_form($fiel
           ),
           // The field_add_more_submit() and field_add_more_js() handlers will
           // find the relevant field using those entries.
+          '#namespace' => $namespace,
           '#field_name' => $field_name,
           '#language' => $langcode,
+          // After build callback to set correct limit_validation_errors
+          '#after_build' => array('field_form_add_more_after_build'),
         );
       }
     }
@@ -297,6 +305,19 @@ function theme_field_multiple_value_form
 }
 
 /**
+ * Sets correct #limit_validation_errors for the 'add_more' button of
+ * fields with unlimited values.
+ *
+ * @see field_multiple_value_form()
+ */
+function field_form_add_more_after_build($element, &$form_state) {
+  $array_parents = $element['#array_parents'];
+  array_pop($array_parents);
+  $element['#limit_validation_errors'] = array($array_parents);
+  return $element;
+}
+
+/**
  * Stores information about the built form structure in the form storage.
  *
  * The 'array_parents' array is used to assign validation errors to actual form
@@ -306,9 +327,10 @@ function theme_field_multiple_value_form
  * @see field_add_more_js()
  */
 function field_form_element_after_build($element, &$form_state) {
+  $namespace = $element['#namespace'];
   $field_name = $element['#field_name'];
   $langcode = $element['#language'];
-  $form_state['field'][$field_name][$langcode]['array_parents'] = $element['#array_parents'];
+  $form_state['field'][$namespace][$field_name][$langcode]['array_parents'] = $element['#array_parents'];
 
   return $element;
 }
@@ -317,8 +339,9 @@ function field_form_element_after_build(
  * Transfer field-level validation errors to widgets.
  */
 function field_default_form_errors($entity_type, $entity, $field, $instance, $langcode, $items, $form, &$form_state) {
+  $namespace = isset($form['#namespace']) ? $form['#namespace'] : 'default';
   $field_name = $field['field_name'];
-  $field_info = $form_state['field'][$field_name][$langcode];
+  $field_info = $form_state['field'][$namespace][$field_name][$langcode];
 
   if (!empty($field_info['errors'])) {
     $function = $instance['widget']['module'] . '_field_widget_error';
@@ -359,10 +382,14 @@ function field_default_form_errors($enti
  * to return just the changed part of the form.
  */
 function field_add_more_submit($form, &$form_state) {
+  $namespace = $form_state['clicked_button']['#namespace'];
   $field_name = $form_state['clicked_button']['#field_name'];
   $langcode = $form_state['clicked_button']['#language'];
-  if ($form_state['values'][$field_name . '_add_more']) {
-    $form_state['field_item_count'][$field_name] = count($form_state['values'][$field_name][$langcode]);
+
+  if ($form_state['values'][$namespace . '_' . $field_name . '_add_more']) {
+    $parents = $form_state['field'][$namespace][$field_name][$langcode]['array_parents'];
+    $values = drupal_array_get_nested_value($form_state['values'], $parents);
+    $form_state['field_item_count'][$namespace][$field_name] = count($values);
   }
   $form_state['rebuild'] = TRUE;
 }
@@ -377,16 +404,17 @@ function field_add_more_submit($form, &$
  */
 function field_add_more_js($form, $form_state) {
   // Retrieve field information.
+  $namespace = $form_state['clicked_button']['#namespace'];
   $field_name = $form_state['clicked_button']['#field_name'];
   $langcode = $form_state['clicked_button']['#language'];
-  $field_info = $form_state['field'][$field_name][$langcode];
+  $field_info = $form_state['field'][$namespace][$field_name][$langcode];
   $field = $field_info['field'];
 
   if ($field['cardinality'] != FIELD_CARDINALITY_UNLIMITED) {
     return;
   }
 
-  // Navigate to the right element in the the form.
+  // Navigate to the right element in the form.
   $element = $form;
 
   foreach ($field_info['array_parents'] as $key) {
Index: modules/field/modules/number/number.module
===================================================================
RCS file: /cvs/drupal/drupal/modules/field/modules/number/number.module,v
retrieving revision 1.43
diff -u -p -r1.43 number.module
--- modules/field/modules/number/number.module	7 Sep 2010 17:56:41 -0000	1.43
+++ modules/field/modules/number/number.module	15 Oct 2010 06:02:09 -0000
@@ -347,6 +347,7 @@ function number_field_widget_form(&$form
   }
 
   $element['#element_validate'][] = 'number_field_widget_validate';
+  $element['#namespace'] = isset($form['#namespace']) ? $form['#namespace'] : 'default';
 
   return array('value' => $element);
 }
@@ -355,8 +356,9 @@ function number_field_widget_form(&$form
  * FAPI validation of an individual number element.
  */
 function number_field_widget_validate($element, &$form_state) {
-  $field = $form_state['field'][$element['#field_name']][$element['#language']]['field'];
-  $instance = $form_state['field'][$element['#field_name']][$element['#language']]['instance'];
+  $namespace = $element['#namespace'];
+  $field = $form_state['field'][$namespace][$element['#field_name']][$element['#language']]['field'];
+  $instance = $form_state['field'][$namespace][$element['#field_name']][$element['#language']]['instance'];
 
   $type = $element['#number_type'];
   $value = $element['#value'];
Index: modules/field/tests/field.test
===================================================================
RCS file: /cvs/drupal/drupal/modules/field/tests/field.test,v
retrieving revision 1.42
diff -u -p -r1.42 field.test
--- modules/field/tests/field.test	28 Sep 2010 02:30:31 -0000	1.42
+++ modules/field/tests/field.test	15 Oct 2010 06:02:09 -0000
@@ -1438,7 +1438,7 @@ class FieldFormTestCase extends FieldTes
     }
     // Press 'add more' button through AJAX, and place the expected HTML result
     // as the tested content.
-    $commands = $this->drupalPostAJAX(NULL, $edit, $this->field_name . '_add_more');
+    $commands = $this->drupalPostAJAX(NULL, $edit, 'default_' . $this->field_name . '_add_more');
     $this->content = $commands[1]['data'];
 
     for ($delta = 0; $delta <= $delta_range; $delta++) {
Index: modules/field_ui/field_ui.admin.inc
===================================================================
RCS file: /cvs/drupal/drupal/modules/field_ui/field_ui.admin.inc,v
retrieving revision 1.72
diff -u -p -r1.72 field_ui.admin.inc
--- modules/field_ui/field_ui.admin.inc	13 Oct 2010 23:46:02 -0000	1.72
+++ modules/field_ui/field_ui.admin.inc	15 Oct 2010 06:02:11 -0000
@@ -1819,8 +1819,6 @@ function field_ui_default_value_widget($
     '#collapsible' => FALSE,
     '#tree' => TRUE,
     '#description' => t('The default value for this field, used when creating new content.'),
-    // Make sure the values appear at the top-level of $form_state['values'].
-    '#parents' => array(),
   );
 
   // Insert the widget.
@@ -1851,7 +1849,7 @@ function field_ui_field_edit_form_valida
     $function(NULL, NULL, $field, $instance, LANGUAGE_NONE, $items, $errors);
   }
   if (isset($errors[$field_name][LANGUAGE_NONE])) {
-    $form_state['field'][$field_name][LANGUAGE_NONE]['errors'] = $errors[$field_name][LANGUAGE_NONE];
+    $form_state['field']['default'][$field_name][LANGUAGE_NONE]['errors'] = $errors[$field_name][LANGUAGE_NONE];
     field_default_form_errors(NULL, NULL, $field, $instance, LANGUAGE_NONE, $items, $form, $form_state);
   }
 }
Index: modules/field_ui/field_ui.test
===================================================================
RCS file: /cvs/drupal/drupal/modules/field_ui/field_ui.test,v
retrieving revision 1.22
diff -u -p -r1.22 field_ui.test
--- modules/field_ui/field_ui.test	11 Sep 2010 00:03:42 -0000	1.22
+++ modules/field_ui/field_ui.test	15 Oct 2010 06:02:11 -0000
@@ -187,8 +187,8 @@ class FieldUITestCase extends DrupalWebT
 
     $langcode = LANGUAGE_NONE;
     $admin_path = 'admin/structure/types/manage/' . $this->hyphen_type . '/fields/' . $field_name;
-    $element_id = "edit-$field_name-$langcode-0-value";
-    $element_name = "{$field_name}[$langcode][0][value]";
+    $element_id = "edit-instance-default-value-widget-$field_name-$langcode-0-value";
+    $element_name = "instance[default_value_widget][{$field_name}][$langcode][0][value]";
     $this->drupalGet($admin_path);
     $this->assertFieldById($element_id, '', t('The default value widget was empty.'));
 
Index: modules/file/file.field.inc
===================================================================
RCS file: /cvs/drupal/drupal/modules/file/file.field.inc,v
retrieving revision 1.35
diff -u -p -r1.35 file.field.inc
--- modules/file/file.field.inc	1 Oct 2010 01:32:59 -0000	1.35
+++ modules/file/file.field.inc	15 Oct 2010 06:02:11 -0000
@@ -441,7 +441,7 @@ function file_field_widget_settings_form
  * Implements hook_field_widget_form().
  */
 function file_field_widget_form(&$form, &$form_state, $field, $instance, $langcode, $items, $delta, $element) {
-
+  $namespace = isset($form['#namespace']) ? $form['#namespace'] : 'default';
   $defaults = array(
     'fid' => 0,
     'display' => !empty($field['settings']['display_default']),
@@ -450,9 +450,18 @@ function file_field_widget_form(&$form, 
 
   // Retrieve any values set in $form_state, as will be the case during AJAX
   // rebuilds of this form.
-  if (isset($form_state['values'][$field['field_name']][$langcode])) {
-    $items = $form_state['values'][$field['field_name']][$langcode];
-    unset($form_state['values'][$field['field_name']][$langcode]);
+  if (isset($form_state['field'][$namespace][$field['field_name']][$langcode]['array_parents'])) {
+    $parents = $form_state['field'][$namespace][$field['field_name']][$langcode]['array_parents'];
+    $values_exists = FALSE;
+    $values = drupal_array_get_nested_value($form_state['values'], $parents, $values_exists);
+    if ($values_exists) {
+      $items = $values;
+      $values = &$form_state['values'];
+      foreach ($parents as $parent) {
+        $values = &$values[$parent];
+      }
+      unset($values);
+    }
   }
 
   foreach ($items as $delta => $item) {
@@ -480,6 +489,7 @@ function file_field_widget_form(&$form, 
     '#process' => array_merge($element_info['#process'], array('file_field_widget_process')),
     // Allows this field to return an array instead of a single value.
     '#extended' => TRUE,
+    '#namespace' => $namespace,
   );
 
   if ($field['cardinality'] == 1) {
@@ -522,6 +532,8 @@ function file_field_widget_form(&$form, 
     // a hook_form_alter().
     $elements['#file_upload_title'] = t('Add a new file');
     $elements['#file_upload_description'] = theme('file_upload_help', array('description' => '', 'upload_validators' => $elements[0]['#upload_validators']));
+
+    $elements['#namespace'] = $namespace;
   }
 
   return $elements;
@@ -580,10 +592,11 @@ function file_field_widget_uri($field, $
  * The #value_callback for the file_generic field element.
  */
 function file_field_widget_value($element, $input = FALSE, $form_state) {
+  $namespace = $element['#namespace'];
   if ($input) {
     // Checkboxes lose their value when empty.
     // If the display field is present make sure its unchecked value is saved.
-    $field = $form_state['field'][$element['#field_name']][$element['#language']]['field'];
+    $field = $form_state['field'][$namespace][$element['#field_name']][$element['#language']]['field'];
     if (empty($input['display'])) {
       $input['display'] = $field['settings']['display_field'] ? 0 : 1;
     }
@@ -608,11 +621,12 @@ function file_field_widget_value($elemen
  * Expands the file_generic type to include the description and display fields.
  */
 function file_field_widget_process($element, &$form_state, $form) {
+  $namespace = $element['#namespace'];
   $item = $element['#value'];
   $item['fid'] = $element['fid']['#value'];
 
-  $field = $form_state['field'][$element['#field_name']][$element['#language']]['field'];
-  $instance = $form_state['field'][$element['#field_name']][$element['#language']]['instance'];
+  $field = $form_state['field'][$namespace][$element['#field_name']][$element['#language']]['field'];
+  $instance = $form_state['field'][$namespace][$element['#field_name']][$element['#language']]['instance'];
   $settings = $instance['widget']['settings'];
 
   $element['#theme'] = 'file_widget';
Index: modules/image/image.field.inc
===================================================================
RCS file: /cvs/drupal/drupal/modules/image/image.field.inc,v
retrieving revision 1.30
diff -u -p -r1.30 image.field.inc
--- modules/image/image.field.inc	4 Oct 2010 18:00:45 -0000	1.30
+++ modules/image/image.field.inc	15 Oct 2010 06:02:12 -0000
@@ -323,10 +323,11 @@ function image_field_widget_form(&$form,
  * Expands the image_image type to include the alt and title fields.
  */
 function image_field_widget_process($element, &$form_state, $form) {
+  $namespace = $element['#namespace'];
   $item = $element['#value'];
   $item['fid'] = $element['fid']['#value'];
 
-  $instance = $form_state['field'][$element['#field_name']][$element['#language']]['instance'];
+  $instance = $form_state['field'][$namespace][$element['#field_name']][$element['#language']]['instance'];
 
   $settings = $instance['settings'];
   $widget_settings = $instance['widget']['settings'];
Index: modules/simpletest/tests/ajax.test
===================================================================
RCS file: /cvs/drupal/drupal/modules/simpletest/tests/ajax.test,v
retrieving revision 1.19
diff -u -p -r1.19 ajax.test
--- modules/simpletest/tests/ajax.test	4 Oct 2010 17:46:01 -0000	1.19
+++ modules/simpletest/tests/ajax.test	15 Oct 2010 06:02:12 -0000
@@ -348,12 +348,13 @@ class AJAXMultiFormTestCase extends AJAX
     // HTML IDs for elements within the field are potentially modified with
     // each AJAX submission, but these variables are stable and help target the
     // desired elements.
+    $namespace = 'default';
     $field_name = 'field_ajax_test';
     $field_xpaths = array(
       'page-node-form' => '//form[@id="page-node-form"]//div[contains(@class, "field-name-field-ajax-test")]',
       'page-node-form--2' => '//form[@id="page-node-form--2"]//div[contains(@class, "field-name-field-ajax-test")]',
     );
-    $button_name = $field_name . '_add_more';
+    $button_name = $namespace . '_' . $field_name . '_add_more';
     $button_value = t('Add another item');
     $button_xpath_suffix = '//input[@name="' . $button_name . '"]';
     $field_items_xpath_suffix = '//input[@type="text"]';
Index: modules/simpletest/tests/form.test
===================================================================
RCS file: /cvs/drupal/drupal/modules/simpletest/tests/form.test,v
retrieving revision 1.72
diff -u -p -r1.72 form.test
--- modules/simpletest/tests/form.test	4 Oct 2010 18:00:46 -0000	1.72
+++ modules/simpletest/tests/form.test	15 Oct 2010 06:02:13 -0000
@@ -1054,7 +1054,7 @@ class FormsRebuildTestCase extends Drupa
     // submission and verify it worked by ensuring the updated page has two text
     // field items in the field for which we just added an item.
     $this->drupalGet('node/add/page');
-    $this->drupalPostAJAX(NULL, array(), array('field_ajax_test_add_more' => t('Add another item')), 'system/ajax', array(), array(), 'page-node-form');
+    $this->drupalPostAJAX(NULL, array(), array('default_field_ajax_test_add_more' => t('Add another item')), 'system/ajax', array(), array(), 'page-node-form');
     $this->assert(count($this->xpath('//div[contains(@class, "field-name-field-ajax-test")]//input[@type="text"]')) == 2, t('AJAX submission succeeded.'));
 
     // Submit the form with the non-AJAX "Save" button, leaving the title field
