How to build multivalue form elements using Form API With the 'field collections' module at the form level, you can create a fieldset (or 'field group') that will accept multiple sets of values. 



Is there a way to do this with the Form API directly (or with the help 'field collections' or 'field group' module) programmatically.  I can make the form fieldset easy enough, but I'm not sure how to set multiple values for this set.  In fact, I'm not really sure how you define multiple values for any field with the Form API.

UPDATE: Just to be clear I want to create the form, not the entity itself (at least not yet).  I want to use the Form API to accomplish this to make my own $form – just the form.
Suppose 'field_page_collection1' is the field collection for the 'page' content type having two text fields 'field_page_collection1_text1', 'field_page_collection1_text2'.

To attach or create field-collection item for node having node id 1.

&lt;?php
$node = node_load(1);
$field_collection_item = entity_create('field_collection_item', array('field_name' =&gt; 'field_page_collection1')); // Create new field collection item.
$field_collection_item-&gt;setHostEntity('node', $node); // Attach it to the node.
$field_collection_item-&gt;field_page_collection1_text1[LANGUAGE_NONE][0]['value'] = 'some value for text field 1'; // Fill value for field_page_collection1_text1.
$field_collection_item-&gt;field_page_collection1_text2[LANGUAGE_NONE][0]['value'] = 'some value for text field 2'; // Fill value for field_page_collection1_text2.
$field_collection_item-&gt;save(); // Save field-collection item.
?&gt;