1 form_example_tutorial.inc | form_example_tutorial_9_add_name($form, &$form_state) |
Submit handler for "Add another name" button on form_example_tutorial_9().
$form_state['num_names'] tells the form builder function how many name fieldsets to build, so here we increment it.
All elements of $form_state are persisted, so there's no need to use a particular key, like the old $form_state['storage']. We can just use $form_state['num_names'].
File
- modules/
examples/ form_example/ form_example_tutorial.inc, line 623 - This is the form API tutorial.
Code
function form_example_tutorial_9_add_name($form, &$form_state) {
// Everything in $form_state is persistent, so we'll just use
// $form_state['add_name']
$form_state['num_names']++;
// Setting $form_state['rebuild'] = TRUE causes the form to be rebuilt again.
$form_state['rebuild'] = TRUE;
}