You are here

function rooms_periodic_pricing_form_rooms_unit_edit_form_validate in Rooms - Drupal Booking for Hotels, B&Bs and Vacation Rentals 7

Validate 'Weekly discount' and 'Monthly discount'.

1 string reference to 'rooms_periodic_pricing_form_rooms_unit_edit_form_validate'
rooms_periodic_pricing_form_rooms_unit_edit_form_alter in modules/rooms_pricing/modules/rooms_periodic_pricing/rooms_periodic_pricing.module
Implements hook_form_FORM_ID_alter().

File

modules/rooms_pricing/modules/rooms_periodic_pricing/rooms_periodic_pricing.module, line 53

Code

function rooms_periodic_pricing_form_rooms_unit_edit_form_validate(&$form, &$form_state) {
  if (empty($form_state['values']['weekly_discount'])) {
    $form_state['values']['weekly_discount'] = '0';
  }
  elseif (!empty($form_state['values']['weekly_discount'])) {
    if (!is_numeric($form_state['values']['weekly_discount'])) {
      form_set_error('weekly_discount', t('%name: you must enter a numeric value for the weekly percentage.', array(
        '%name' => t('Weekly discount'),
      )));
    }
    elseif ($form_state['values']['weekly_discount'] < 0 || $form_state['values']['weekly_discount'] > 100) {
      form_set_error('weekly_discount', t('%name: you must enter a valid value for the weekly percentage.', array(
        '%name' => t('Weekly discount'),
      )));
    }
  }
  if (empty($form_state['values']['monthly_discount'])) {
    $form_state['values']['monthly_discount'] = '0';
  }
  elseif (!empty($form_state['values']['monthly_discount'])) {
    if (!is_numeric($form_state['values']['monthly_discount'])) {
      form_set_error('monthly_discount', t('%name: you must enter a numeric value for the monthly percentage.', array(
        '%name' => t('Monthly discount'),
      )));
    }
    elseif ($form_state['values']['monthly_discount'] < 0 || $form_state['values']['monthly_discount'] > 100) {
      form_set_error('weekly_discount', t('%name: you must enter a valid value for the monthly percentage.', array(
        '%name' => t('Monthly discount'),
      )));
    }
  }
}