function poll_more_choices_submit in Drupal 7
Same name and namespace in other branches
- 6 modules/poll/poll.module \poll_more_choices_submit()
Submit handler to add more choices to a poll form.
This handler is run regardless of whether JS is enabled or not. It makes changes to the form state. If the button was clicked with JS disabled, then the page is reloaded with the complete rebuilt form. If the button was clicked with JS enabled, then ajax_form_callback() calls poll_choice_js() to return just the changed part of the form.
1 string reference to 'poll_more_choices_submit'
- poll_form in modules/
poll/ poll.module - Implements hook_form().
File
- modules/
poll/ poll.module, line 366 - Enables your site to capture votes on different topics in the form of multiple choice questions.
Code
function poll_more_choices_submit($form, &$form_state) {
// If this is a Ajax POST, add 1, otherwise add 5 more choices to the form.
if ($form_state['values']['poll_more']) {
$n = $_GET['q'] == 'system/ajax' ? 1 : 5;
$form_state['choice_count'] = count($form_state['values']['choice']) + $n;
}
// Renumber the choices. This invalidates the corresponding key/value
// associations in $form_state['input'], so clear that out. This requires
// poll_form() to rebuild the choices with the values in
// $form_state['node']->choice, which it does.
$form_state['node']->choice = array_values($form_state['values']['choice']);
unset($form_state['input']['choice']);
$form_state['rebuild'] = TRUE;
}