poll_validate

  1. drupal
    1. 4.7
    2. 5 poll.module
    3. 6 poll.module
    4. 7 poll.module
Versions
4.7 – 6 poll_validate($node)
7 poll_validate($node, $form)

Implementation of hook_validate().

Code

modules/poll.module, line 105

<?php
function poll_validate($node) {
  if (isset($node->title)) {
    // 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++;
      }
      if ($choice['chvotes'] < 0) {
        form_set_error("choice][$i][chvotes", t('Negative values are not allowed.'));
      }
    }

    if ($realchoices < 2) {
      form_set_error("choice][$realchoices][chtext", t('You must fill in at least two choices.'));
    }
  }
}
?>