function advpoll_ranking_submit in Advanced Poll 7        
                          
                  
                        Same name and namespace in other branches
- 7.3 advpoll_ranking/advpoll_ranking.module \advpoll_ranking_submit()
- 7.2 advpoll_ranking/advpoll_ranking.module \advpoll_ranking_submit()
1 string reference to 'advpoll_ranking_submit'
  - advpoll_ranking_choice_form in advpoll_ranking/advpoll_ranking.module
File
 
   - advpoll_ranking/advpoll_ranking.module, line 312
Code
function advpoll_ranking_submit($form, &$form_state) {
  $data = advpoll_get_form_data($form_state);
  $count = count($data->choices);
  $nid = $form_state['build_info']['args'][0]->nid;
  $votes = array();
  
  $writein = '';
  $message = advpoll_form_submit_check($data, $nid);
  if ($message) {
    $form['message'] = array(
      '#type' => 'markup',
      '#prefix' => '<div id="message">',
      '#suffix' => '</div>',
      '#markup' => $message,
    );
    return $form;
  }
  
  if ($data->write_in) {
    if (isset($form_state['values']['write_in'])) {
      $writein = trim($form_state['values']['write_in']);
      $writein_weight = $form_state['values']['write_in_weight'];
      
      $writein = filter_xss($writein);
      $writein = check_plain($writein);
      
      if ($writein_weight == 'no-js' || $writein_weight > 0) {
        if ($writein) {
          $writein_choice = advpoll_process_writein($nid, $writein, $data);
          $data->choices[] = $writein_choice;
          if ($writein_weight == 'no-js') {
            $writein_weight = 1;
          }
          $votes[] = array(
            'rank' => $writein_weight,
            'id' => $writein_choice['choice_id'],
          );
        }
        else {
          if ($writein_weight != 'no-js') {
            
            $form['message'] = array(
              '#type' => 'markup',
              '#prefix' => '<div id="message">',
              '#suffix' => '</div>',
              '#markup' => t('Please type in a valid write-in choice or select a different option.'),
            );
            return $form;
          }
        }
      }
    }
  }
  
  if ($data->max_choices > 1 || !$votes) {
    $votes = advpoll_ranking_process_results($form_state['values']['choice'], $data->choices, $votes);
  }
  if (count($votes) > 0 && count($votes) <= $data->max_choices) {
    advpoll_ranking_process_votes($data, $nid, $votes);
    if ($data->behavior == 'borda') {
      $element['#markup'] = advpoll_display_borda_results($nid, $data);
    }
    else {
      $element['#markup'] = advpoll_display_runoff_results($nid, $data);
    }
    return $element;
  }
  else {
    $form['message'] = array(
      '#type' => 'markup',
      '#prefix' => '<div id="message">',
      '#suffix' => '</div>',
      '#markup' => t('Select up to @quantity @votes.', array(
        '@quantity' => $data->max_choices,
        '@votes' => format_plural($data->max_choices, 'vote', 'votes'),
      )),
    );
    return $form;
  }
}