PHP Datepicker

Hi all,

I am working on a contact form which requires the user to pick a date. I would like to have something similar to this one, http://www.allcarrentacar.com/, with a few tweaks.

  1. I would like users to only pick from as many days as there are in the selected month (ie, cannot pick Feb. 30)

2)I don’t need pick up time, or any drop off info

  1. I would like add the year, but allow users to choose only 2010 or 2011

  2. I would like to use minimal JS, mainly PHP if possible.

I have tried to figure this out from scratch, but I think it is beyond my skill set. I even tried downloading some free scripts, but cannot seem to implement them properly.

Any ideas where I can find an easy to use script or a solid tutorial? Thanks in advance!

~ Lauren:confused:

It’s all free. You won’t regret taking a bit of time to learn it.

Ok, I don’t mind the size, so where can I get the jQuery UI datepicker? Can I just purchase it and download it from someplace? Sorry, I am still pretty new at this. Thanks!

Lauren

The calendar you linked to is most likely this one:

http://www.dynarch.com/projects/calendar/

I’ve seen it before and it is a JS calendar but my personal favorite date picker is the jQuery UI datepicker. I know you said minimal JS, but the jQuery UI datepicker is ridiculously easy to use despite dropping a couple hundred KB on the page.

That said, if you want to roll some sort of server-side solution, that makes things a little more difficult. You may find the CalendarEvent class in:

http://barebonescms.com/documentation/webcron/

To be useful. It could be used like:

require_once "calendar_event.php";

$year = date("Y");
$month = date("m");
$cal = new CalendarEvent();
$currcal = $cal->GetCalendar($year, $month, true);

var_dump($currcal);

Then $currcal contains all the information you need to construct a calendar fairly easily in HTML. Here’s what the above code generates for October 2010 (this month):

array(10) {
[“success”]=>
bool(true)
[“year”]=>
string(4) “2010”
[“month”]=>
string(2) “10”
[“prevmonthnumdays”]=>
string(2) “30”
[“weekdays”]=>
array(7) {
[“sun”]=>
int(1)
[“mon”]=>
int(2)
[“tue”]=>
int(3)
[“wed”]=>
int(4)
[“thu”]=>
int(5)
[“fri”]=>
int(6)
[“sat”]=>
int(7)
}
[“firstweekdaypos”]=>
int(6)
[“numdays”]=>
string(2) “31”
[“numweeks”]=>
int(6)
[“nextmonthweekdaypos”]=>
int(2)
[“calendar”]=>
array(0) {
}
}

Calendars are almost always displayed using HTML tables. I would use ‘firstweekdaypos’ to determine how many empty cells to create for the first row. October 1 starts on Friday. Then, count off 31 days (‘numdays’) for the month being careful to close each ‘tr’ at the end of each week and starting another row if the last day of the month hasn’t been reached yet. Then fill out the last row with empty cells.

If you want to get really fancy, some calendars show greyed out days of the surrounding months. ‘prevmonthnumdays’ contains the number of days in September. Since Friday is the first day of October, Sunday would be Sept 26. Filling in remaining days after the current month is a lot easier. Instead of empty cells, just start counting at ‘1’ and go from there to the end of the row.

I still think the jQuery UI route is the best.

Thanks! Got it all downloaded and extracted. Now trying to get it to work. I’ll let ya know how it goes :slight_smile:

~Lauren