Date Time Code
  Home arrow Date Time Code arrow FutureDateFormEntry.php
Codewalker Forums 
  Tutorials  
Database Articles  
Miscellaneous  
Navigation Usability  
PEAR Articles  
Programming Basics  
Server Administration  
XML Tutorials  
  Reviews  
Database Book Reviews  
Linux Book Reviews  
Miscellaneous Reviews  
PHP Book Reviews  
PHP Software Reviews  
Server Admin Reviews  
SQL Tool Reviews  
  Code Gallery  
Content Management Code  
Contest Code  
Counters Code  
Database Code  
Date Time Code  
Discussion Board Code  
Email Code  
File Manipulation Code  
GUI Code  
Link Farm Code  
Miscellaneous Code  
Search Code  
Site Navigation Code  
User Management Code  
Mobile Linux 
App Generation ROI 
IBM® developerWorks 
Download TestComplete 
Forums Sitemap 
Weekly Newsletter 
 
Developer Updates  
Free Website Content 
 RSS  Articles
 RSS  Forums
 RSS  All Feeds
Write For Us Get Paid 
Request Media Kit
Contact Us 
Site Map 
Privacy Policy 
Support 
 USERNAME
 
 PASSWORD
 
 
  >>> SIGN UP!  
  Lost Password? 
DATE TIME CODE

FutureDateFormEntry.php
By: Codewalkers
  • Search For More Articles!
  • Disclaimer
  • Author Terms
  • Rating: 4 stars4 stars4 stars4 stars4 stars / 2
    2006-10-12

    Table of Contents:

    Rate this Article: Poor Best 
      ADD THIS ARTICLE TO:
      Del.ici.ous Digg
      Blink Simpy
      Google Spurl
      Y! MyWeb Furl
    Email Me Similar Content When Posted
    Add Developer Shed Article Feed To Your Site
    Email Article To Friend
    Print Version Of Article
    PDF Version Of Article
     
     
    ADVERTISEMENT


    PLEASE NOTE:

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

    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.

    validFutureDate():
    Checks that entry is indeed a valid future date.


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



    By : dsilvia

    <?php
    /*
    * (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
    * dsilvia@mchsi.com
    *
    */
    /*
    * 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:

    <?php
    include('FutureDateFormEntry.php');
    $userName=$_REQUEST[yourName];
    $enteredDay=$_REQUEST[expiryDay];
    $enteredMonth=$_REQUEST[expiryMonth];
    $enteredYear=$_REQUEST[expiryYear];
    $goodEntry=true;
    $entryMade=($enteredDay && $enteredMonth && $enteredYear);
    if($entryMade)
    $goodEntry=validFutureDate($enteredDay,$enteredMonth,$enteredYear);
    ?>
    <html>
    <head>
    <title>Untitled</title>
    </head>
    <body>
    <?php
    if($entryMade && !$userName)
    {
    print("Name field is empty<br />");
    }
    if(!$goodEntry)
    {
    print($enteredDay."/".$enteredMonth."/".$enteredYear." is not in the future<br />");
    }
    elseif($entryMade)
    {
    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">
    </form>
    </body>
    </html>

    *
    * $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,
    $order='dmy',
    $plusDays=0,
    $plusMonths=1,
    $plusYears=0,
    $futureYears=1,
    $dayName='expiryDay',
    $monthName='expiryMonth',
    $yearName='expiryYear'
    )
    {
    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!
    */
    $lastDay=array(0,31,28,31,30,31,30,31,31,30,31,30,31);
    $today=getdate();
    $tDay=$today[mday];
    $tMon=$today[mon];
    $tYear=$today[year];
    if($tMon == 12)
    {
    $theYear++;
    }
    if($defaultDay && $defaultMonth && $defaultYear)
    {
    if(!validFutureDate($defaultDay,$defaultMonth,$defaultYear))
    {
    unset($defaultDay,$defaultMonth,$defaultYear);
    }
    }
    $theDay=$tDay+$plusDays;
    $theMonth=$tMon+$plusMonths;
    if($theMonth > 12) $theMonth-=12;
    $theYear=$tYear+$plusYears;
    if($theDay > $lastDay[$theMonth]) $theDay=$lastDay[$theMonth];
    if($defaultDay) $theDay=$defaultDay;
    if($defaultMonth) $theMonth=$defaultMonth;
    if($defaultYear) $theYear=$defaultYear;
    $mSelect=array_pad(array(''),13,'');
    $mSelect[$theMonth]='selected';
    $dSelect=array_pad(array(''),32,'');
    $dSelect[$theDay]='selected';

    $entryStr='';
    for($i=0; $i < 3; $i++)
    {
    if($order[$i] == "m")
    $entryStr.='
    <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>
    </select>';
    if($order[$i] == "d")
    $entryStr.='
    <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>
    </select>';
    if($order[$i] == "y")
    {
    $entryStr.='
    <select name="'.$yearName.'">';
    for($j=$tYear; $j < $theYear; $j++)
    {
    $entryStr.='
    <option value="'.$j.'">'.$j.'</option>';
    }
    $entryStr.='
    <option selected value="'.$theYear.'">'.$theYear.'</option>';
    for($j=1; $j <= $futureYears; $j++)
    {
    $nYear=$theYear+$j;
    $entryStr.='
    <option value="'.$nYear.'">'.$nYear.'</option>';
    }
    $entryStr.='
    </select>';
    }
    }

    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)
    {
    $today=getdate();
    $tDay=$today[mday];
    $tMon=$today[mon];
    $tYear=$today[year];
    $cmpMon=$theMonth;
    $goodDate=true;
    if($theYear > $tYear)
    {
    $cmpMon+=12;
    }
    /* is it in the 'long' past? */
    if($cmpMon < $tMon)
    {
    $goodDate=false;
    }
    /* is it recent past or today? */
    elseif($theDay <= $tDay && $cmpMon == $tMon && $theYear == $tYear)
    {
    $goodDate=false;
    }
    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

     

    IBM® developerWorks developerWorks - FREE Tools!


    NEW! Evaluate IBM Rational Developer for System i V7.1

    Download a free trial version of IBM Rational Developer for System i V7.1, which provides a complete development environment for traditional i5/OS application development. IBM Rational Developer for System i is a new eclipse-based workstation offering for i5/OS application development that provides a comprehensive Integrated Development Environment for edit/compile/debug of traditional RPG/COBOL/C/C++ i5/OS applications.
    FREE! Go There Now!


    NEW! Harnessing the power of SQL and Java for high performance data access

    Join this webcast to see how IBM Data Studio Developer and pureQuery can take the pain out of Java data access. uApplications developed using both Java and SQL have become a common requirement. Database connectivity using Java Database Connectivity (JDBC) to create an application is a multi-step tedious process, and tooling that covers both SQL and Java has been unavailable, until now. IBM Data Studio introduces the pureQuery platform: a high-performance, Java data access platform focused on simplifying the tasks of developing, managing, and optimizing database applications and services.
    FREE! Go There Now!


    NEW! Hello World: Learn how to install and use the Rational Asset Manager Eclipse client

    In this tutorial, you can learn how to install and configure the IBM Rational Asset Manager Eclipse client, explore the different views in the Asset Management perspective, learn various search techniques, work with existing assets, and submit a new asset.
    FREE! Go There Now!


    NEW! Improve your build process with IBM Rational Build Forge, Part 1: Create a continuous build and integration environment

    Learn how to implement a build management system that uses and extends your existing automation technologies. This tutorial shows, step-by-step, how to install and configure IBM Rational Build Forge to manage builds for Jakarta Tomcat from source code.
    FREE! Go There Now!


    NEW! Rational Talks to You: Manage RUP-based CMMI initiatives

    Join this Rational Talks to You teleconference on December 4 at 1:00 pm ET to discuss how Rational Method Composer can help meet your compliance objectives. Get your questions answered!
    FREE! Go There Now!


    NEW! Section 508 of the U.S. Rehabilitation Act: Web accessibility compliance

    Because access to government information continues to be an area of concern for many U.S. citizens with disabilities, the U.S. government enacted Section 508 of the Rehabilitation Act in 2001 to ensure that government agencies create accessible Web content, enabling all citizens to access the information they need. A fully accessible Web site makes Web content accessible to all individuals, including those with disabilities, who may be accessing Web content via a variety of user agents. Common user agents include standard Web browsers, text-only browsers, assistive devices and mobile devices such as cell phones or personal digital assistants (PDAs).
    FREE! Go There Now!


    NEW! Trial download: IBM Rational Functional Tester V7.0.1

    Get a free trial download of the latest version of IBM Rational Functional Tester V7.0.1. Rational Functional Tester is an automated functional and regression testing solution for QA teams concerned with the quality of their Java, Microsoft Visual Studio .NET, and Web-based applications.
    FREE! Go There Now!


    NEW! Try the IBM SOA Sandbox for People

    Visit IBM developerWorks to try the IBM SOA Sandbox for people. The SOA Sandbox for people provides a trial environment with the necessary tooling and components required to enable consistent human and process interaction and collaboration, showing how you can improve user experience and business productivity.
    FREE! Go There Now!


    NEW! Webcast: Application security testing and Web compliance

    Join the IBM Watchfire team for an informative discussion on techniques and best practices to proactively manage Web application security and how to effectively build application security testing into the software development lifecycle (SDLC). In this Software Delivery Platform webcast you will learn: How to better understand potential web application security vulnerabilities, best practices and how to effectively integrate application security testing into the software development lifecycle, the importance of detecting and removing software vulnerabilities during application development.
    FREE! Go There Now!


    NEW! Webcast: Introducing the new Information Server and Solutions community: LeverageInformation

    User communities play an important role in communication and collaboration around products, solutions and other areas of special interest to members. Successful communities are able to provide the right mix of content and services to deliver a value proposition that resonates with each audience. Join Tom Inman, VP of Marketing for Information and Platform Solutions as he introduces the new LeverageINFORMATION community. During this webcast, learn about the value provided by the community and how customers and partners derive value from the community in addressing their own technical and business challenges.
    FREE! Go There Now!



    All FREE IBM® developerWorks Tools!

    DATE TIME CODE ARTICLES

    - 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





    © 2003-2009 by Developer Shed. All rights reserved. DS Cluster 3 Hosted by Hostway
    Stay green...Green IT