You are here

function commerce_price_field_widget_validate in Commerce Core 7

Validate callback: ensures the amount value is numeric and converts it from a decimal value to an integer price amount.

1 string reference to 'commerce_price_field_widget_validate'
commerce_price_field_widget_form in modules/price/commerce_price.module
Implements hook_field_widget_form().

File

modules/price/commerce_price.module, line 744
Defines the Price field with widgets and formatters used to add prices with currency codes to various Commerce entities.

Code

function commerce_price_field_widget_validate($element, &$form_state) {
  if ($element['amount']['#value'] !== '') {

    // Ensure the price is numeric.
    if (!is_numeric($element['amount']['#value'])) {
      form_error($element['amount'], t('%title: you must enter a numeric value for the price amount.', array(
        '%title' => $element['amount']['#title'],
      )));
    }
    else {

      // Convert the decimal amount value entered to an integer based amount value.
      form_set_value($element['amount'], commerce_currency_decimal_to_amount($element['amount']['#value'], $element['currency_code']['#value']), $form_state);
    }
  }
}