function rooms_form_start_end_dates_validate in Rooms - Drupal Booking for Hotels, B&Bs and Vacation Rentals 7
Validation callback that could be reused in all the forms that need to validate dates. End date must be greater than start date.
6 string references to 'rooms_form_start_end_dates_validate'
- rooms_availability_update_status_form in modules/
rooms_availability/ rooms_availability.module - Form to manage the availability for specific month.
- rooms_booking_availability_search_form_builder in modules/
rooms_booking_manager/ rooms_booking_manager.availability_search.inc - Form callback for rooms_booking_availability_search_form_builder.
- rooms_booking_edit_form in modules/
rooms_booking/ rooms_booking.admin.inc - Form callback: create or edit a booking.
- rooms_pricing_update_form in modules/
rooms_pricing/ rooms_pricing.module - Form to manage the room units pricing.
- update_availability_calendar_form in modules/
rooms_availability/ rooms_availability.module - A basic form that allows us to update the state of the calendar.
File
- ./
rooms.module, line 998 - Provides basic underlying functionality and configuration options used by all Rooms modules
Code
function rooms_form_start_end_dates_validate($form, &$form_state) {
list($start_date, $end_date) = rooms_form_input_get_start_end_dates($form_state);
$today_greater = FALSE;
$single_day_bookings = FALSE;
// Skip if no dates are provided.
if (empty($start_date) || empty($end_date)) {
form_set_error('date_range', t('Please choose dates.'));
return;
}
// In case that this value is set trigger the today greater validation.
if (isset($form_state['today_greater_validation'])) {
$today_greater = TRUE;
}
// In case that this value is set trigger the today greater validation.
if (isset($form_state['single_day_bookings'])) {
$single_day_bookings = TRUE;
}
else {
// Set the form state so that we can carry the value over to the results page
$form_state['single_day_bookings'] = $single_day_bookings;
}
// Check date validity.
$errors = rooms_check_dates_validity($start_date, $end_date, $today_greater, $single_day_bookings);
// For some forms as rooms_availability_pricing_update_form and
// rooms_availability_update_status_form we need to validate that the selected
// date match with current values.
if (isset($form_state['values']['curr_month']) && isset($form_state['values']['curr_year'])) {
$curr_month = $form_state['values']['curr_month'];
$curr_year = $form_state['values']['curr_year'];
if ($start_date
->format('n') != $curr_month || $end_date
->format('n') != $curr_month || $start_date
->format('Y') != $curr_year || $end_date
->format('Y') != $curr_year) {
$errors[] = t('Start and end date must be within the current month.');
}
}
// When there are multiples errors for the same form element Drupal only
// display the first. Here we concatenate to display all at once.
if ($errors) {
$error_msg = implode(' ', $errors);
form_set_error('date_range', $error_msg);
}
}