Multiple textfield values im using form api and im trying to get to make a group of fields under one type, like for example a phone number, you would have 3 fields 1 being the area code and the other 2 fields being the number

I would think it would be something like this..

$form['phone'] = array(

    '#title' =&gt; 'Phone Number',
    '#tree' =&gt; TRUE
);

$form['phone']['areacode'] = array(
    '#type' =&gt; 'textfield',
    '#maxlength' =&gt; 3,
    '#size' =&gt; 3,
);

$form['phone']['number1'] = array(
    '#type' =&gt; 'textfield',
    '#maxlength' =&gt; 3,
    '#size' =&gt; 3,
);

    $form['phone']['number2'] = array(
    '#type' =&gt; 'textfield',
    '#maxlength' =&gt; 4,
    '#size' =&gt; 4,
);


or even something with options like this for example

$form['phone'] = array(
    '#type' =&gt; 'textfield',
    '#title' =&gt; 'Phone Number',
    '#tree' =&gt; TRUE,
    '#options' =&gt; array(
        array(
        '#value' =&gt; t('areacode'),
        '#maxlength' =&gt; 3,
        'size' =&gt; 3,
        ),
        array(
        '#value' =&gt; t('number1'),
        '#maxlength' =&gt; 3,
        'size' =&gt; 3,
        ),
        array(
        '#value' =&gt; t('number2'),
        '#maxlength' =&gt; 4,
        'size' =&gt; 4,
        ),

    )
);


Either way I want to have multiple textfield values under one form type.

Thanks
I know there are some parent and tree properties in the form API, but to be honest I have never use it. In a case like your I will create 3 text fields with a limit number of characters depending on the part of the phone number I am collecting ( 3 (for area code) - 3 (for the exchange) - 4 (for the number) ) and then on the submit function of the form I will concatenated them together.

function my_module_example_form($form, &amp;$form_state) {

// If you edit the data using the same form then 
// get the previously store phone number
$phone = $phone_from_db;

$form['area-code'] = array(
  '#type' =&gt; 'textfield', 
  '#title' =&gt; t('Area Code'), 
  '#default_value' =&gt; substr($phone, 0, 3), 
  '#size' =&gt; 3, 
  '#maxlength' =&gt; 3, 
  '#required' =&gt; TRUE,
);

$form['exchange'] = array(
  '#type' =&gt; 'textfield', 
  '#title' =&gt; t('Exchange'), 
  '#default_value' =&gt; substr($phone, 3, 3), 
  '#size' =&gt; 3, 
  '#maxlength' =&gt; 3, 
  '#required' =&gt; TRUE,
);

$form['number'] = array(
  '#type' =&gt; 'textfield', 
  '#title' =&gt; t('Number'), 
  '#default_value' =&gt; substr($phone, 6, 4), 
  '#size' =&gt; 4, 
  '#maxlength' =&gt; 4, 
  '#required' =&gt; TRUE,
);

  return $form;
}

function my_module_example_form_submit($form, &amp;$form_state) {
  // Submission logic.
  $phone = $form_state['values']['area-code']+$form_state['values']['exchange']+$form_state['values']['number'];
  // Save the $phone variable 
}


There are also a couple of modules with the ability to add phone fields and they even offer validation of the phone number depending on the country.


http://drupal.org/project/phone
http://drupal.org/project/cck_phone
http://drupal.org/project/location