Relate number of values to an integer field I was wondering how to do this with drupal. You probably wonder why I don't just use the unlimited amount of values setting. That's because I want to require the user to fill in the amount of values related to the integer value.

For example, you want to create a group (node) for a specific category (node). A category which contains an integer field (field_members). Now lets say you also have a node reference field (field_category) at those group node its fields, which refers to a specific category (in this case field_members). Then the user must add the amount of users related to the category its field_members value.
You will probably have to setup some way of two step process to enable the reference between both nodes (maybe entityreference). The field you are using will have to be an unlimited multi value field.

with this peace of code you will be able to reduce the items of that field (including the add button). Feel free to provide any other logic for looking up the settings node / proding a default limit etc.

&lt;?php
function mymodule_field_attach_form($entity_type, $entity, &amp;$form, &amp;$form_state, $langcode) {
  if ($entity_type == 'node' &amp;&amp; $entity-&gt;type == 'my_content_type') {
    $multi_values = array();
    foreach ($form['field_myfield'][LANGUAGE_NONE] as $key =&gt; $value) {
      if (is_numeric($key)) {
        $multi_values[$key] = $value;
      }
    }

    if (count($multi_values) &gt; 1) {
      $multi_value_keys = array_keys($multi_values);
      foreach ($multi_value_keys as $key) {
        unset($form['field_myfield'][LANGUAGE_NONE][$key]);
      }

      // get the count of the asociated node, maybe using entity reference?
      $settings_node = node_load($entity-&gt;field_settings_node[0][LANGUAGE_NONE]['target_id']);
      if ($settings_node) {
        $limit = $settings_node-&gt;field_limiting_field[LANGUAGE_NONE][0]['value']; // e.g. textfield..
        if ($limit) {
          $i = 0;
          // add all the fields that are allowed, cut of the once that are too much (and remove the add button)
          while ($i &lt; $limit &amp;&amp; $i &lt; count($multi_values)) {
            $form['field_myfield'][LANGUAGE_NONE][$i] = array_shift($multi_values);
            $i++;
          }
        }
      }
    }
  }
}


You might also want to look at How to dynamically set the maximum cardinality for a multi value field? for another example (setting the access attribute for those fields)