Question: With the 'field collections' module at the form level, you can create a fieldset (or 'field group') that will accept multiple sets of values. 

![enter image description here](https://i.stack.imgur.com/xfNYE.png)

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.

Answer: 
Modify your example\_form\_form1\_submit function as follows

```
function example_form_form1_submit(&$form, &$form_state) {
  variable_set('id_event', $form_state['values']['id_event']);
  $id_event = variable_get('id_event', '');
  drupal_set_message($id_event);
}

```

![enter image description here](https://i.stack.imgur.com/SAYKM.png)
Drupal's variable API allows for storage of persistent variables across separate requests.

If you want to set a Drupal variable, you need to use [variable\_set()](http://api.drupal.org/api/drupal/includes%21bootstrap.inc/function/variable_set/6).

Example:

```
$my_variable = 'very_important_value';          // Here we set a php variable

variable_set('my_variable_name', $my_variable); // Here we store the php variable
                                                // into a Drupal variable

```

If you want to retrieve the Drupal variable's value, you need to use [variable\_get()](http://api.drupal.org/api/drupal/includes%21bootstrap.inc/function/variable_get/6).

```
$saved_value = variable_get('my_variable_name', 'default_value'); // Get the value of the
                                                                  // Drupal variable. If
                                                                  // it does not exist, then
                                                                  // use the second argument

```

You are seeing the value stored correctly in the database because you are making use of **variable\_set()** correctly. However, when you are trying to retrieve the value, you need to be sure to call **variable\_get()** to retrieve the value and store it into a php variable for further usage.

Suggestion:

```
function example_form_form1_submit(&$form, &$form_state) {

  variable_set('id_event', $form_state['values']['id_event']); // Stores the value

  $saved_value = variable_get('id_event', 'Default');          // Retrieve the stored value.
                                                               // If it is not saved,
                                                               // $saved_value will be set
                                                               // to 'Default'.
  drupal_set_message($saved_value);
}

```