You are here

function uc_attribute_option_form_validate in Ubercart 6.2

Same name and namespace in other branches
  1. 5 uc_attribute/uc_attribute.module \uc_attribute_option_form_validate()
  2. 7.3 uc_attribute/uc_attribute.admin.inc \uc_attribute_option_form_validate()

Validates number formats.

See also

uc_attribute_option_form()

uc_attribute_option_form_submit()

File

uc_attribute/uc_attribute.admin.inc, line 561
Attribute administration menu items.

Code

function uc_attribute_option_form_validate($form, &$form_state) {
  $pattern = '/^-?\\d*(\\.\\d*)?$/';
  $price_error = t('This must be in a valid number format. No commas and only one decimal point.');
  if (!is_numeric($form_state['values']['cost']['#value']) && !preg_match($pattern, $form_state['values']['cost']['#value'])) {
    form_set_error('cost', $price_error);
  }
  if (!is_numeric($form_state['values']['price']['#value']) && !preg_match($pattern, $form_state['values']['price']['#value'])) {
    form_set_error('price', $price_error);
  }
  if (!is_numeric($form_state['values']['weight']['#value']) && !preg_match($pattern, $form_state['values']['weight']['#value'])) {
    form_set_error('weight', $price_error);
  }
}