summaryrefslogtreecommitdiff
path: root/modules/poll/poll.module
diff options
context:
space:
mode:
Diffstat (limited to 'modules/poll/poll.module')
-rw-r--r--modules/poll/poll.module14
1 files changed, 8 insertions, 6 deletions
diff --git a/modules/poll/poll.module b/modules/poll/poll.module
index 13d2606de..614bb9240 100644
--- a/modules/poll/poll.module
+++ b/modules/poll/poll.module
@@ -288,9 +288,10 @@ function poll_form($node, &$form_state) {
// Add initial or additional choices.
$existing_delta = $delta;
- $weight++;
for ($delta; $delta < $choice_count; $delta++) {
$key = 'new:' . ($delta - $existing_delta);
+ // Increase the weight of each new choice.
+ $weight++;
$form['choice_wrapper']['choice'][$key] = _poll_choice_form($key, NULL, '', 0, $weight, $choice_count);
}
@@ -408,6 +409,7 @@ function _poll_choice_form($key, $chid = NULL, $value = '', $votes = 0, $weight
'#maxlength' => 7,
'#parents' => array('choice', $key, 'chvotes'),
'#access' => user_access('administer nodes'),
+ '#element_validate' => array('element_validate_integer'),
);
$form['weight'] = array(
@@ -451,10 +453,8 @@ function poll_node_form_submit(&$form, &$form_state) {
*/
function poll_validate($node, $form) {
if (isset($node->title)) {
- // Check for at least two options and validate amount of votes:
+ // Check for at least two options and validate amount of votes.
$realchoices = 0;
- // Renumber fields
- $node->choice = array_values($node->choice);
foreach ($node->choice as $i => $choice) {
if ($choice['chtext'] != '') {
$realchoices++;
@@ -586,8 +586,10 @@ function poll_update($node) {
'weight' => $choice['weight'],
))
->insertFields(array(
- 'nid' => $node->nid,
- 'chtext' => $choice['chtext'],
+ 'nid' => $node->nid,
+ 'chtext' => $choice['chtext'],
+ 'chvotes' => (int) $choice['chvotes'],
+ 'weight' => $choice['weight'],
))
->execute();
}