You are here

function _advpoll_writeins_voting_form_validate in Advanced Poll 5

Same name and namespace in other branches
  1. 6.3 advpoll.module \_advpoll_writeins_voting_form_validate()
  2. 6 advpoll.module \_advpoll_writeins_voting_form_validate()
  3. 6.2 advpoll.module \_advpoll_writeins_voting_form_validate()

Voting form validation logic specific to writeins. This has been abstracted away from includes in the modes directory.

2 calls to _advpoll_writeins_voting_form_validate()
advpoll_voting_binary_form_validate in modes/binary.inc
Check if the submitted key exists, just to make sure the form is not bypassed.
advpoll_voting_ranking_form_validate in modes/ranking.inc
Implementation of the vote validation hook for the runoff module.

File

./advpoll.module, line 1476
Advanced Poll - a sophisticated polling module for voting, elections, and group decision-making.

Code

function _advpoll_writeins_voting_form_validate($node, $writein_option, $writein_text, $ajax) {

  // Do write-in specific checks if write-ins are enabled and user has permission.
  if ($node->writeins && user_access('add write-ins')) {

    // Something is in the write-in textbox.
    if ($writein_text) {
      $writein_choice_lower = strtolower($writein_text);
      foreach ($node->choice as $i => $value) {

        // Check that user isn't writing in an existing visible choice. (User is
        // writing in an existing choice and either write-ins are all being
        // displayed or the existing choice is not a write-in).
        if (strtolower($val['label']) == $writein_choice_lower && ($node->show_writeins || !$value['writein'])) {
          _advpoll_form_set_error('writein_choice', t("A write-in vote can not be for an existing choice. Select the choice's option instead."), $ajax);
        }
      }
    }

    // The write-in option is selected and there is nothing in the write-in textbox.
    if ($writein_option && !$writein_text) {
      _advpoll_form_set_error('writein_choice', t('If the "write-in" option is selected, a choice must be written in.'), $ajax);
    }

    // The write-in option is not selected, but there is something in the write-in textbox.
    if (!$writein_option && $writein_text) {
      _advpoll_form_set_error('writein_choice', t('If a choice is written in, the "write-in" option must be selected.'), $ajax);
    }
  }
}