Definition

auction_bid_form_validate($form_id, $form_values)
ecommerce-5--4/contrib/auction/auction.module, line 96

Description

Checks that a new bid is valid. Currently, it simply checks that the bid is a number and is higher than the previous bid.

Code

<?php
function auction_bid_form_validate($form_id, $form_values) {
  $errors = array();

  if (isset($form_values['bid'])) {
    if (is_numeric($form_values['bid'])) {
      if (!empty($form_values['price'])) {
        // check if the bid price is higher than the actual
        // bid and if the user put more than 2 decimal places
        // on bid price, which is forbidden
        if ($form_values['bid'] <= $form_values['price'] or
            round($form_values['bid'], 2) != $form_values['bid']) {
          $errors['bid'] = t('You must bid more than %current-price.',
            array('%current-price' => format_currency($form_values['price'])));
        }
      }
    }
    else {
      $errors['bid'] = t('You must enter a price.');
    }
  }

  // In case of any errors
  if (!empty($errors)) {
    foreach ($errors as $name => $message) {
      form_set_error($name, $message);
    }
  }
}
?>