function uc_product_validate in Ubercart 6.2
Same name and namespace in other branches
- 5 uc_product/uc_product.module \uc_product_validate()
Implements hook_validate().
Ensures that prices, weight, dimensions, and quantity are positive numbers.
File
- uc_product/
uc_product.module, line 633 - The product module for Ubercart.
Code
function uc_product_validate($node) {
$pattern = '/^\\d*(\\.\\d*)?$/';
$price_error = t('Price must be in a valid number format. No commas and only one decimal point.');
if (!empty($node->list_price) && !is_numeric($node->list_price) && !preg_match($pattern, $node->list_price)) {
form_set_error('list_price', $price_error);
}
if (!empty($node->cost) && !is_numeric($node->cost) && !preg_match($pattern, $node->cost)) {
form_set_error('cost', $price_error);
}
if (!is_numeric($node->sell_price) && !preg_match($pattern, $node->sell_price)) {
form_set_error('sell_price', $price_error);
}
foreach (array(
'weight',
'length',
'width',
'height',
) as $property) {
if (!empty($node->{$property}) && (!is_numeric($node->{$property}) || $node->{$property} < 0)) {
form_set_error($property, t('@property must be a positive number. No commas and only one decimal point.', array(
'@property' => ucfirst($property),
)));
}
}
}