I've looked at the form_example (number 8) for dynamic forms, based on this I've done
$form['line'] = array(
'#type' => 'fieldset',
'#title' => t('Order Items'),
'#collapsible' => FALSE,
'#collapsed' => FALSE,
);
for ($next = 1; $next <= $linecount; $next++)
{
$form['line'][$next] = array(
'#type' => 'fieldset',
'#title' => t('Line Item: ') . $next,
'#collapsible' => FALSE,
'#collapsed' => FALSE,
);
$form['line'][$next]['qty'] = array(
'#type' => 'textfield',
'#size' => 3,
'#default_value' => $form_state['values']['line'][$next]['qty'],
'#title' => t('Quantity')
);
}
However, when the data is submitted $form_state['values']['line'] is empty but there is a $form_state['values']['qty'] containing the value entered on the form.
If I change the form to
$form['line'][$next]['qty-'.$next]
I get
$form_state['values']['qty-1']
$form_state['values']['qty-2']
$form_state['values']['qty-nnn']
rather than
$form_state['values']['line']['qty-1']
Any suggestions on how I can get the data in an array?
I'm wanting a final end state of
$form_state['values']['line'][1]['qty']
$form_state['values']['line'][1]['prod_id']
$form_state['values']['line'][1]['...']
$form_state['values']['line'][2]['qty']
$form_state['values']['line'][2]['prod_id']