You are here

function advpoll_checkbox_selected in Advanced Poll 7.3

Same name and namespace in other branches
  1. 7 includes/advpoll_voteapi.inc \advpoll_checkbox_selected()
  2. 7.2 includes/advpoll_voteapi.inc \advpoll_checkbox_selected()

Processes votes cast via checkboxes.

Checkbox values returned by form_state have a different structure than radio buttons. We need an array of indexes representing items selected from list of choices.

Parameters

array $choices: An array containing available choices in the poll.

array $votes: Text of choices selected from the form_state. Need to match them up with choices saved in the node.

Return value

array The the unique IDs of the choices selected by the user.

1 call to advpoll_checkbox_selected()
advpoll_form_submit in ./advpoll.module
Submit handler for voting.

File

includes/advpoll_voteapi.inc, line 383
Advanced Poll Vote API Include.

Code

function advpoll_checkbox_selected($choices, $votes) {
  $selected = array();
  $count = count($choices);
  for ($i = 0; $i < $count; $i++) {
    $choice = strip_tags($choices[$i]['choice_id']);
    if (isset($votes[$choice]) && ctype_xdigit($votes[$choice]) && !empty($votes[$choice])) {
      $selected[] = $choices[$i]['choice_id'];
    }
  }
  return $selected;
}