You are here

function makemeeting_choices_submit in Make Meeting Scheduler 7.2

Submit handler to add more choices or suggestions to a poll form, or to copy the first row of suggestions to the others

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 makemeeting_choice_js() to return just the changed part of the form.

2 string references to 'makemeeting_choices_submit'
makemeeting_field_widget_form in ./makemeeting.field.inc
Implements hook_field_widget_form().
_makemeeting_choice_form in ./makemeeting.field.inc
Helper function to construct a row of the widget form

File

./makemeeting.field.inc, line 528
This file is mostly about the field configuration.

Code

function makemeeting_choices_submit($form, &$form_state) {
  $clicked_button = $form_state['clicked_button'];

  // Get the element
  $element =& drupal_array_get_nested_value($form_state['input'], $clicked_button['#parents']);

  // If clicked button is 'Remove', unset corresponding choice
  if ($clicked_button['#value'] == t('Remove')) {
    unset($element['choices'][$clicked_button['#name']]);
    $form_state['choice_count'] = count($element['choices']);
  }

  // Affect timestamp as key to each choice
  $choices = array();
  if (isset($element['choices'])) {
    foreach ($element['choices'] as $choice) {
      $dateTime = _makemeeting_date_timestamp($choice['chdate']);
      $choices['choices'][$dateTime
        ->format('d-m-Y')] = $choice;
    }
  }

  // Handle other operations
  if (!empty($form_state['values']['op'])) {
    switch ($form_state['values']['op']) {

      // Add 1 more choice to the form.
      case t('More choices'):

        // Increment choice count
        $form_state['choice_count'] = count($element['choices']) + 1;
        break;

      // Add 1 more suggestion to the form.
      case t('More suggestions'):
        $form_state['suggestion_count']++;
        break;

      // Copy first row suggestions to the other rows.
      case t('Copy and paste first row'):
        $first = reset($choices['choices']);
        foreach (array_keys($choices['choices']) as $key) {
          $choices['choices'][$key]['chsuggestions'] = $first['chsuggestions'];
        }
        break;
    }
  }

  // Replace submitted values by our own work
  drupal_array_set_nested_value($form_state['input'], $clicked_button['#parents'], $choices);
  drupal_array_set_nested_value($form_state['values'], $clicked_button['#parents'], $choices);

  // Require the widget form to rebuild the choices
  // with the values in $form_state
  $form_state['rebuild'] = TRUE;
}