• This site uses cookies. By continuing to use this site, you are agreeing to our use of cookies. Learn more.

RESOLVED Datepicker for PHP Snippet

Messages
12
Likes
0
Points
1
#1
I'm looking for an alternative to the HTML5 datepicker for my PHP code generated FORM. It mostly works but is not great. Is there an alternative which will work in my PHP Snippet which is is either internal to WordPress or included in jQuery or as another plugin.
Thanks, Dave W.
 
Messages
12
Likes
0
Points
1
#3
Thank you Temyk,
It was a little tricky since I had to add the wp_enqueue calls.
Here's the final code which works, and was included at the beginning of my Woody Snippet Script.
Any suggestions to improve on this.
Dave.

wp_enqueue_script('jquery-ui-datepicker');
wp_enqueue_style('jquery-ui-css', 'http://ajax.googleapis.com/ajax/libs/jqueryui/1.8.2/themes/smoothness/jquery-ui.css');
print <<<DATE
<script>
$( function() {
$( ".datepicker" ).datepicker({
dateFormat:"yy-mm-dd",
changeMonth: true,
changeYear: true,
yearRange: "1945:c"
});
} );
</script>
DATE;
 
Messages
12
Likes
0
Points
1
#4
Well it worked ... and then it stopped working. So I copied the jQuery code that was working but stopped working into a very simple new page with a FORM that has 2 date fields so that I could work with it, but I still can't get it to work. I have used basically the same JS code in a stand_alone PHP program and it works fine. Can you offer any help.
Thanks, Dave.
BTW I hope I inserted the PHP code properly.
Here's the WordPress link if it can help Date Picker - Canadian Aikido Federation

PHP:
wp_enqueue_script('jquery-ui-datepicker');
wp_enqueue_style('jquery-ui-css', 'http://ajax.googleapis.com/ajax/libs/jqueryui/1.8.2/themes/smoothness/jquery-ui.css');
print <<<DATE
<script>
$( function() {
$( ".datepicker" ).datepicker({
dateFormat:"yy-mm-dd",
changeMonth: true,
changeYear: true,
yearRange: "1945:c"
});
});
</script>
DATE;

print "<B>POST </B>".print_r($_POST,true)."<BR>";

print <<<FORM
<form method='POST'>
<p>Input Date1: <input type="text" class="datepicker" name="date1" value=""></p>
<p>Input Date2: <input type="text" class="datepicker" name="date2" value=""></p>
<input type="submit" name="submit" value="Submit">
</post>
FORM;
 
Messages
12
Likes
0
Points
1
#5
Problem solved!

While looking at some other examples of datepickers I noticed a different way of programming the $( function line in JS. I tried the different way and it worked. I hope this fixes it permanently.
Thanks, Dave.