Code: Select all
<?php
/*
* Drop Down Date Maker by Steve Geer
*
* Purpose:
* To make a dropdown menu based on the next XX days.
*
* Utility:
* Helpful for times when the user needs to schedule something
* and a set range of dates needs to be set. For example, you
* have a Tennis Organization, and you would like to allow the
* user to schedule a lesson a week in advance. Removes the
* need for validation scripts to make sure that the date is not
* already taken (kinda) or an invalid format.
*
* This script stores the value of the date chosen in the POST
* variable $apptdate, but feel free to change it as you see fit.
* The date is stored as MySQL compatible DATE format YYYY-MM-DD.
* You can change this in the "value" attribute of the <option>
* element.
*
* Copyrights:
* No, no. I looked online and couldn't find much in the way of
* a script like this, so I just typed one out myself. I am proud
* of it, but doubt it will be used much. If you do use it, let me
* know, eh?
*
* Resources:
* http://forums.devnetwork.net/
* http://www.phpfreaks.com/forums/
* http://www.hotscripts.com/
* `PHP & MySQL Web Development` by Luke Welling and Laura Thomson
*
*/
if(isset($_POST['appt'])){
echo $_POST['appt'];
}
?>
<form action="<?php $_SERVER['PHP_SELF']?>" method="post">
<select name="appt">
<?php
$t = mktime(); //initial timestamp
$td = getdate($t); //formatted date
//Change the limit to the amount of days you need it to "see" into the future.
//In this example it is going 31 days into the future. Why not 32? 31 is < 32.
for($i=0;$i<32;$i++){
//create the initial timestamp:
$t2 = mktime($td['hours'], $td['minutes'], 0, $td['mon'], ($td['mday']+5)+$i, $td['year']);
//formats the timestamp created above:
$td2 = getdate($t2);
//makes the HTML option values:
echo '<option name="apptdate" value="'.$td2['year'].'-'.$td2['mon'].'-'.$td2['mday'].'">';
echo $td2['mon'].'/'.$td2['mday'].'/'.$td2['year'];
echo '</option>';
}
?>
</select>
<input type="submit">
</form>