| Versions | |
|---|---|
| 4.7 | poll_view_voting(&$node, |
| 5 | poll_view_voting($node, $block) |
| 6 | poll_view_voting(&$form_state, $node, $block) |
| 7 | poll_view_voting($form, &$form_state, $node, $block = FALSE) |
Generates the voting form for a poll.
modules/
<?php
function poll_view_voting(&$node, $teaser, $page, $block) {
// Check for a valid form token to protect against cross site request forgeries.
if ($_POST['op'] == t('Vote') && drupal_valid_token($_POST['edit']['form_token'], 'poll_view_voting', TRUE)) {
poll_vote($node);
}
if ($node->choice) {
$list = array();
foreach ($node->choice as $i => $choice) {
$list[$i] = check_plain($choice['chtext']);
}
$form['choice'] = array(
'#type' => 'radios',
'#title' => $block ? check_plain($node->title) : '',
'#default_value' => -1,
'#options' => $list,
);
}
$form['nid'] = array(
'#type' => 'hidden',
'#value' => $node->nid,
);
$form['vote'] = array(
'#type' => 'submit',
'#value' => t('Vote'),
);
$form['#action'] = url('node/' . $node->nid);
return drupal_get_form('poll_view_voting', $form);
}
?>