Access values from multiple field forms as elements of one form I'm trying to create entities from my custom form. To do that, I created "Add more" button, where I'm dynamically adding new elements that I'm attaching fields to by using:

field_attach_form('myentity', $entity, $form['wrapper']['myentities'][$key]['fields'], $form_state);


I would like to create entities in submit callback with field values from those elements.

The problem is, that when I have a multiple elements, inputs for the same type of fields of different entities have the same "name" attribute (eg. field_myfield[und][0][value]), which means that I can access only the value from the field of the last entity in the submit callback, which means that I cannot fill my entity with proper values before saving. I tried to put '#tree' => TRUE up the form tree, and unset this value on field level, but it didn't change an input name, and "values" structure.

How can I have in my submit callback access to all of the field values, so I could use them for creating entities?
You need to use the #parents variable as documented in the field_attach_form page. 
See field_attach_form