You are here

function advpoll_validate_max_choices in Advanced Poll 7

Same name and namespace in other branches
  1. 7.3 advpoll.module \advpoll_validate_max_choices()
  2. 7.2 advpoll.module \advpoll_validate_max_choices()
1 string reference to 'advpoll_validate_max_choices'
advpoll_form_alter in ./advpoll.module

File

./advpoll.module, line 336

Code

function advpoll_validate_max_choices($element, &$form_state, $form) {
  $input_choices = array();
  $lang = $form_state['build_info']['args'][0]->language;
  $choices = $form_state['input']['advpoll_choice'][$lang];
  foreach ($choices as $choice) {
    if ($choice['choice']) {
      $input_choices[] = $choice['choice'];
    }
  }
  $max = (int) $element['#value'];
  if ($max > count($input_choices)) {
    form_error($element, t('The max number of choices is @max.', array(
      '@max' => $max,
    )));
  }
  if (count($input_choices) < 2) {
    form_set_error('advpoll_choice', t('Please enter at least two choices.'));
  }
}