function poll_vote

7.x poll.module poll_vote($form, &$form_state)
6.x poll.module poll_vote($form, &$form_state)

Submit handler for processing a vote.

14 string references to 'poll_vote'
PollVoteCheckHostname::testHostnamePollVote in drupal-7.x/modules/poll/poll.test
Check that anonymous users with same ip cannot vote on poll more than once unless user is logged in.
poll_cancel in drupal-7.x/modules/poll/poll.module
Submit callback for poll_cancel_form().
poll_delete in drupal-7.x/modules/poll/poll.module
Implements hook_delete().
poll_load in drupal-7.x/modules/poll/poll.module
Implements hook_load().
poll_schema in drupal-7.x/modules/poll/poll.install
Implements hook_schema().

... See full list

File

drupal-7.x/modules/poll/poll.module, line 759
Enables your site to capture votes on different topics in the form of multiple choice questions.

Code

function poll_vote($form, &$form_state) {
  $node = $form['#node'];
  $choice = $form_state['values']['choice'];

  global $user;
  db_insert('poll_vote')
    ->fields(array(
      'nid' => $node->nid,
      'chid' => $choice,
      'uid' => $user->uid,
      'hostname' => ip_address(),
      'timestamp' => REQUEST_TIME,
    ))
    ->execute();

  // Add one to the votes.
  db_update('poll_choice')
    ->expression('chvotes', 'chvotes + 1')
    ->condition('chid', $choice)
    ->execute();

  cache_clear_all();

  if (!$user->uid) {
    // The vote is recorded so the user gets the result view instead of the
    // voting form when viewing the poll. Saving a value in $_SESSION has the
    // convenient side effect of preventing the user from hitting the page
    // cache. When anonymous voting is allowed, the page cache should only
    // contain the voting form, not the results.
    $_SESSION['poll_vote'][$node->nid] = $choice;
  }

  drupal_set_message(t('Your vote was recorded.'));

  // Return the user to whatever page they voted from.
}