ontarget
Active Member
Hi I have a calendar viz which triggers a form when you double click on the event date in the cal.
I allow users to enter a "Arrival Date" and "Departure Date" and some other basic info into the form.
The system admin can tick a check box called "Accept Booking" which stores a value ["Booked"] in the DB
I wish to prevent other users from entering data into any cells between the Arrival and Departure dates after the admin has ticked "Booked" so i need some kind of date range validation.
The isunique values plugin works great if they select the "Arrival Date or Departure Date" as they are stored in the database - but doesn't cut the mustard for a range of dates as users can still select dates in-between.
I tried the following code (thanks to Rob for his post) as php validation on the "arrival Date" element
'bookings___date_time' and as a php plugin on the bookings form.
Unfortunately not working - no errors returned on the element php validation.
On the form php plugin it makes the form popup blank - maybe thats good!?
Here is the code - would really appreciate any help
I allow users to enter a "Arrival Date" and "Departure Date" and some other basic info into the form.
The system admin can tick a check box called "Accept Booking" which stores a value ["Booked"] in the DB
I wish to prevent other users from entering data into any cells between the Arrival and Departure dates after the admin has ticked "Booked" so i need some kind of date range validation.
The isunique values plugin works great if they select the "Arrival Date or Departure Date" as they are stored in the database - but doesn't cut the mustard for a range of dates as users can still select dates in-between.
I tried the following code (thanks to Rob for his post) as php validation on the "arrival Date" element
'bookings___date_time' and as a php plugin on the bookings form.
Unfortunately not working - no errors returned on the element php validation.
On the form php plugin it makes the form popup blank - maybe thats good!?
Here is the code - would really appreciate any help
PHP:
// Get the form field's value:
//arrival date hidden date field
$date = '{bookings___date_time}';
//departure date
$enddate = '{bookings___date_time_dep}';
// Get the db object
$db =JFactory::getDbo();
// Quote the values for security reasons:
$date = $db->quote($date);
// Build the query
$query = $db->getQuery(true);
$query->SELECT ('count(*)')
->FROM('bookings')
->WHERE('date_time >= ' . $date .' AND date_time_dep <= ' . $enddate .' AND accept_booking =' .["Booked"]);
$db->setQuery($query);
// Run the query
$found = $db->loadResult();
if ($found == 1) {
return false;
} else {
return true;
}