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

2 string references to 'poll_vote'
poll_theme in drupal-6.x/modules/poll/poll.module
Implementation of hook_theme()
poll_view_voting in drupal-6.x/modules/poll/poll.module
Generates the voting form for a poll.

File

drupal-6.x/modules/poll/poll.module, line 588
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;
  if ($user->uid) {
    db_query('INSERT INTO {poll_votes} (nid, chorder, uid) VALUES (%d, %d, %d)', $node->nid, $choice, $user->uid);
  }
  else {
    db_query("INSERT INTO {poll_votes} (nid, chorder, hostname) VALUES (%d, %d, '%s')", $node->nid, $choice, ip_address());
  }

  // Add one to the votes.
  db_query("UPDATE {poll_choices} SET chvotes = chvotes + 1 WHERE nid = %d AND chorder = %d", $node->nid, $choice);

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

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