| 7 form_example_tutorial.inc | form_example_tutorial_9_add_name($form, &$form_state) |
| 8 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'].
1 string reference to 'form_example_tutorial_9_add_name'
File
- form_example/
form_example_tutorial.inc, line 633 - This is the Form API Tutorial from the handbook.
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;
}
Login or register to post comments