function commerce_price_field_validate in Commerce Core 7
Implements hook_field_validate().
File
- modules/
price/ commerce_price.module, line 68 - Defines the Price field with widgets and formatters used to add prices with currency codes to various Commerce entities.
Code
function commerce_price_field_validate($entity_type, $entity, $field, $instance, $langcode, &$items, &$errors) {
$translated_instance = commerce_i18n_object('field_instance', $instance);
// Ensure only numeric values are entered in price fields.
foreach ($items as $delta => &$item) {
if (!empty($item['amount']) && !is_numeric($item['amount'])) {
$errors[$field['field_name']][$langcode][$delta][] = array(
'error' => 'price_numeric',
'message' => t('%name: you must enter a numeric value for the price.', array(
'%name' => $translated_instance['label'],
)),
);
}
}
}