Date Time Code

  Home arrow Date Time Code arrow FutureDateFormEntry.php

By: Codewalkers
  • Search For More Articles!
  • Disclaimer
  • Author Terms
  • Rating: 4 stars4 stars4 stars4 stars4 stars / 2

    Table of Contents:




    This is code to generate a selection entry form for a future date, not a
    function to validate dates.

    Quick, easy addition of future date fields to HTML code using PHP.
    Handy for requesting expiration dates, dates for delivery, dates for
    appointments, or any web application that requires obtaining a future
    date from the user.

    Checks that entry is indeed a valid future date.

    Code introduction comment contains a fully functional example for illustrative/testing purposes.

    By : dsilvia

    * (c) 2006, D.E. Silvia, All rights reserved.
    * This code is available for use for non-commercial purposes.
    * Free to distribute as long as this copyright information remains intact.
    * No modification is authorized. Please, refer bugs/enhancements to
    * futureDateFormEntry():
    * Quick, easy addition of future date fields to HTML code using PHP.
    * Handy for requesting expiration dates, dates for delivery, dates for
    * appointments, or any web application that requires obtaining a future
    * date from the user.
    * Function requires only 3 arguments if you are happy with the defaults:
    * The 3 required arguments are a mechanism for preserving the user's valid
    * input from previous edits of the form (re-entrant form code). They may
    * be NULL, in which case the default selection parameters apply.
    * Example:

    $entryMade=($enteredDay && $enteredMonth && $enteredYear);
    if($entryMade && !$userName)
    print("Name field is empty<br />");
    print($enteredDay."/".$enteredMonth."/".$enteredYear." is not in the future<br />");
    print($enteredDay."/".$enteredMonth."/".$enteredYear." is a valid future date<br />");
    <form method="post" action="test.php">
    <input name="yourName" type="text" value="<?php print($userName); ?>">&nbsp; Your Name<br />
    <?php print(futureDateFormEntry($enteredDay,$enteredMonth,$enteredYear)); ?>
    &nbsp; Give me some date in the Future<br />
    <input name="gotEntry" type="submit" value="Submit">

    * $defaultDay: Specific day (may be NULL)
    * $defaultMonth: Specific month (may be NULL)
    * $defaultYear: Specific year (may be NULL)
    * $order='dmy': Euro convention of day:month:year
    * $alignment='left': standard; can be any "<td align=" value
    * default selections:
    * $plusDays=0: assumes same day of month as today's or maximum day
    * for the given month; number of days you want added
    * to today's month day
    * $plusMonths=1: one month in the future; number of months you want
    * added to today's month
    * $plusYears=0: current year or next year if current month is 12 [Dec];
    * number of years you want added to today's year
    * $futureYears=1: number of years in the future to include in selection
    * beyond the default selected year.
    * <select name="input-name":
    * $dayName='expiryDay'
    * $monthName='expiryMonth'
    * $yearName='expiryYear'
    function futureDateFormEntry($defaultDay,$defaultMonth,$defaultYear,
    if($plusYears > $futureYears) $futureYears=$plusYears;
    * Yes, I know, this array doesn't account for leap years! So? Is that really a problem?
    * The user can always select the 29th of February anyway!
    if($tMon == 12)
    if($defaultDay && $defaultMonth && $defaultYear)
    if($theMonth > 12) $theMonth-=12;
    if($theDay > $lastDay[$theMonth]) $theDay=$lastDay[$theMonth];
    if($defaultDay) $theDay=$defaultDay;
    if($defaultMonth) $theMonth=$defaultMonth;
    if($defaultYear) $theYear=$defaultYear;

    for($i=0; $i < 3; $i++)
    if($order[$i] == "m")
    <select name="'.$monthName.'">
    <option '.$mSelect[1].' value="1">1 [Jan]</option><option '.$mSelect[2].' value="2">2 [Feb]</option>
    <option '.$mSelect[3].' value="3">3 [Mar]</option><option '.$mSelect[4].' value="4">4 [Apr]</option>
    <option '.$mSelect[5].' value="5">5 [May]</option><option '.$mSelect[6].' value="6">6 [Jun]</option>
    <option '.$mSelect[7].' value="7">7 [Jul]</option><option '.$mSelect[8].' value="8">8 [Aug]</option>
    <option '.$mSelect[9].' value="9">9 [Sep]</option><option '.$mSelect[10].' value="10">10 [Oct]</option>
    <option '.$mSelect[11].' value="11">11 [Nov]</option><option '.$mSelect[12].' value="12">12 [Dec]</option>
    if($order[$i] == "d")
    <select name="'.$dayName.'">
    <option '.$dSelect[1].' value="1">&nbsp;1</option><option '.$dSelect[2].' value="2">&nbsp;2</option>
    <option '.$dSelect[3].' value="3">&nbsp;3</option><option '.$dSelect[4].' value="4">&nbsp;4</option>
    <option '.$dSelect[5].' value="5">&nbsp;5</option><option '.$dSelect[6].' value="6">&nbsp;6</option>
    <option '.$dSelect[7].' value="7">&nbsp;7</option><option '.$dSelect[8].' value="8">&nbsp;8</option>
    <option '.$dSelect[9].' value="9">&nbsp;9</option><option '.$dSelect[10].' value="10">10</option>
    <option '.$dSelect[11].' value="11">11</option><option '.$dSelect[12].' value="12">12</option>
    <option '.$dSelect[13].' value="13">13</option><option '.$dSelect[14].' value="14">14</option>
    <option '.$dSelect[15].' value="15">15</option><option '.$dSelect[16].' value="16">16</option>
    <option '.$dSelect[17].' value="17">17</option><option '.$dSelect[18].' value="18">18</option>
    <option '.$dSelect[19].' value="19">19</option><option '.$dSelect[20].' value="20">20</option>
    <option '.$dSelect[21].' value="21">21</option><option '.$dSelect[22].' value="22">22</option>
    <option '.$dSelect[23].' value="23">23</option><option '.$dSelect[24].' value="24">24</option>
    <option '.$dSelect[25].' value="25">25</option><option '.$dSelect[26].' value="26">26</option>
    <option '.$dSelect[27].' value="27">27</option><option '.$dSelect[28].' value="28">28</option>
    <option '.$dSelect[29].' value="29">29</option><option '.$dSelect[30].' value="30">30</option>
    <option '.$dSelect[31].' value="31">31</option>
    if($order[$i] == "y")
    <select name="'.$yearName.'">';
    for($j=$tYear; $j < $theYear; $j++)
    <option value="'.$j.'">'.$j.'</option>';
    <option selected value="'.$theYear.'">'.$theYear.'</option>';
    for($j=1; $j <= $futureYears; $j++)
    <option value="'.$nYear.'">'.$nYear.'</option>';

    return $entryStr;

    * argument values are assumed to be returns from a form entry generated
    * by futureDateFormEntry(). As such, the year can never be in the past.
    function validFutureDate($theDay,$theMonth,$theYear)
    if($theYear > $tYear)
    /* is it in the 'long' past? */
    if($cmpMon < $tMon)
    /* is it recent past or today? */
    elseif($theDay <= $tDay && $cmpMon == $tMon && $theYear == $tYear)
    return $goodDate;

    DISCLAIMER: The content provided in this article is not warranted or guaranteed by Developer Shed, Inc. The content provided is intended for entertainment and/or educational purposes in order to introduce to the reader key ideas, concepts, and/or product reviews. As such it is incumbent upon the reader to employ real-world tactics for security and implementation of best practices. We are not liable for any negative consequences that may result from implementing any information covered in our articles or tutorials. If this is a hardware review, it is not recommended to open and/or modify your hardware.

    More Date Time Code Articles
    More By Codewalkers

    blog comments powered by Disqus


    - DaysInSpan.php
    - MySQLdateSpan.php
    - DateSpan.php
    - FutureDateFormEntry.php
    - Generate Time Option List for Select stateme...
    - Current Age Script (v2)
    - class for some mysql imitated time functions
    - Current Age Script, up to the last day
    - filemtime_remote
    - Page Generation Time Figure-Outer
    - convGMT v2
    - Benchmarker
    - Simple PHP Calendar
    - Display message according to hour of day
    - Display Date Function

    Developer Shed Affiliates


    © 2003-2018 by Developer Shed. All rights reserved. DS Cluster - Follow our Sitemap