You are here

function advpoll_choice_form in Advanced Poll 7

Same name and namespace in other branches
  1. 7.3 advpoll.module \advpoll_choice_form()
  2. 7.2 advpoll.module \advpoll_choice_form()
2 string references to 'advpoll_choice_form'
advpoll_cancel_vote_submit in ./advpoll.module
advpoll_node_view in ./advpoll.module
Implements hook_node_view().

File

./advpoll.module, line 472

Code

function advpoll_choice_form($form, &$form_state, $values) {
  $data = advpoll_get_data($values);
  $count = count($data->choices);
  $options = array();
  $form['#id'] = 'advpoll-form-' . $values->nid;
  for ($i = 0; $i < $count; $i++) {
    if (!$data->choices[$i]['write_in']) {
      $options[] = strip_tags($data->choices[$i]['choice']);
    }
  }
  $options = drupal_map_assoc($options);
  $input_type = 'radios';
  if ($data->max_choices > 1) {
    $input_type = 'checkboxes';
  }
  if ($data->write_in && $data->mode != 'unlimited') {
    $options['write-in'] = t('(Write-in)');
    $form['choice_' + $count] = array(
      '#type' => $input_type,
      '#title' => '',
      '#options' => $options,
      '#ajax' => array(
        'callback' => 'advpoll_writein_callback',
        'wrapper' => 'advpoll-form-' . $values->nid,
        'effect' => 'fade',
      ),
    );
    if (isset($form_state['values'])) {
      foreach ($form_state['values'] as $key => $item) {
        if (is_numeric($key)) {
          break;
        }
      }
      $selected = false;
      if ($input_type == 'radios') {
        if ($item === 'write-in') {
          $selected = true;
        }
      }
      else {
        if ($item['write-in']) {
          $selected = true;
        }
      }
      if ($selected) {
        $form['write_in'] = array(
          '#type' => 'textfield',
          '#element_validate' => array(
            'advpoll_writein_validate',
          ),
          '#prefix' => '<div class="advpoll-write-in">',
          '#suffix' => '</div>',
          '#size' => '30',
        );
      }
    }
  }
  else {
    $form['choice_' + $count] = array(
      '#type' => $input_type,
      '#title' => '',
      '#options' => drupal_map_assoc($options),
    );
  }
  $form['submit'] = array(
    '#type' => 'submit',
    '#ajax' => array(
      'callback' => 'advpoll_form_submit',
      'wrapper' => 'advpoll-form-' . $values->nid,
      'name' => 'submit1',
    ),
    '#value' => t('Vote'),
  );
  return $form;
}