poll_vote
- Versions
- 4.6 – 5
poll_vote(&$node)- 6 – 7
poll_vote($form, &$form_state)
Submit handler for processing a vote.
Code
modules/poll/poll.module, line 684
<?php
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' => $user->uid ? ip_address() : '',
))
->execute();
// Add one to the votes.
db_update('poll_choice')
->expression('chvotes', 'chvotes + 1')
->condition('chid', $choice)
->execute();
cache_clear_all();
drupal_set_message(t('Your vote was recorded.'));
// Return the user to whatever page they voted from.
}
?>Login or register to post comments 