function ajax_example_dynamic_sections_submit in Examples for Developers 7
Submit function for ajax_example_dynamic_sections().
Related topics
File
- ajax_example/
ajax_example_graceful_degradation.inc, line 297 - Demonstrations of AJAX with graceful degradation.
Code
function ajax_example_dynamic_sections_submit($form, &$form_state) {
// This is only executed when a button is pressed, not when the AJAXified
// select is changed.
// Now handle the case of the next, previous, and submit buttons.
// Only submit will result in actual submission, all others rebuild.
switch ($form_state['triggering_element']['#value']) {
case t('Submit your answer'):
// Submit: We're done.
$form_state['rebuild'] = FALSE;
$answer = $form_state['values']['question'];
// Special handling for the checkbox.
if ($answer == 1 && $form['questions_fieldset']['question']['#type'] == 'checkbox') {
$answer = $form['questions_fieldset']['question']['#title'];
}
if ($answer === t('George Washington')) {
drupal_set_message(t('You got the right answer: @answer', array(
'@answer' => $answer,
)));
}
else {
drupal_set_message(t('Sorry, your answer (@answer) is wrong', array(
'@answer' => $answer,
)));
}
return;
// Any other form element will cause rebuild of the form and present
// it again.
case t('Choose'):
$form_state['values']['question_type_select'] = $form_state['input']['question_type_select'];
// Fall through.
default:
$form_state['rebuild'] = TRUE;
}
}