function form_example_tutorial_9_add_name

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'].

Related topics

1 string reference to 'form_example_tutorial_9_add_name'
form_example_tutorial_9 in form_example/form_example_tutorial.inc
Example 9: A form with a dynamically added new fields.

File

form_example/form_example_tutorial.inc, line 667

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;
}