poll_form
- Versions
- 4.6 – 4.7
poll_form(&$node)- 5
poll_form($node,$form_values= NULL)- 6
poll_form(&$node, $form_state)- 7
poll_form($node, &$form_state)
Implementation of hook_form().
Code
modules/poll.module, line 119
<?php
function poll_form(&$node) {
$admin = user_access('administer nodes');
if (function_exists('taxonomy_node_form')) {
$output = implode('', taxonomy_node_form('poll', $node));
}
if (!isset($node->choices)) {
$node->choices = max(2, count($node->choice) ? count($node->choice) : 5);
}
// User ticked 'need more choices'.
if ($node->morechoices) {
$node->choices *= 2;
}
$output .= '<div class="poll-form">';
// Poll choices
$opts = drupal_map_assoc(range(2, $node->choices * 2 + 5));
for ($a = 0; $a < $node->choices; $a++) {
$group1 .= form_textfield(t('Choice %n', array('%n' => ($a + 1))), "choice][$a][chtext", $node->choice[$a]['chtext'], 50, 127);
if ($admin) {
$group1 .= form_textfield(t('Votes for choice %n', array('%n' => ($a + 1))), "choice][$a][chvotes", (int)$node->choice[$a]['chvotes'], 7, 7);
}
}
$group1 .= form_hidden('choices', $node->choices);
$group1 .= form_checkbox(t('Need more choices'), 'morechoices', 1, 0, t("If the amount of boxes above isn't enough, check this box and click the Preview button below to add some more."));
$output .= form_group(t('Choices'), $group1);
// Poll attributes
$_duration = array(0 => t('Unlimited')) + drupal_map_assoc(array(86400, 172800, 345600, 604800, 1209600, 2419200, 4838400, 9676800, 31536000), "format_interval");
$_active = array(0 => t('Closed'), 1 => t('Active'));
if ($admin) {
$group2 .= form_radios(t('Poll status'), 'active', isset($node->active) ? $node->active : 1, $_active, t('When a poll is closed, visitors can no longer vote for it.'));
}
$group2 .= form_select(t('Poll duration'), 'runtime', $node->runtime ? $node->runtime : 0, $_duration, t('After this period, the poll will be closed automatically.'));
$output .= form_group(t('Settings'), $group2);
$output .= '</div>';
return $output;
}
?>Login or register to post comments 