Forum for discussing general topics related to Couch.
4 posts Page 1 of 1
Hi, I am wondering if this is possible.

I have a form for booking a hotel room. The form has a field for Arrival and one for Departure. Each of these fields has a jquery datepicker that allows the user to easily select the date. The date is then outputted in the following format: 02/02/2012.

I want to be able to compare the 2 fields and if the Departure is before the Arrival, display an error.

Any help would be appreciated as I'm not really sure where to start.

Thanks in advance.

I should add that I am using the Couch form field functions.
I'm sure there is a great php solution for this to check the date values after submission, but you may also want to prompt the user as they are entering the values. I incorporated a script I found on stackoverflow with jQuery. Depending on where you are from and what date format you use, this may need to be slightly modified:
http://jsfiddle.net/hLZYH/
@mark Couch form fields support custom validation by PHP code so we can create and attach such a routine to one of the date fields to check for acceptable values.

If you could paste in a link to a working version of your form (with JQuery datepicker) or post in a working HTML version, I'll try and code up a validation routine for you.

I'd like to add though that, as @cheesypoof suggested, for a form that doesn't get persisted into a database, a JavaScript validation solution seems to be sufficient and more user-friendly - more so since your form is already using JQuery.
Take your pick.
Thanks for the replies.

I ended up using the solution Cheesypoof suggested. Works well.

Cheers.
4 posts Page 1 of 1