Menu

Adding a Date Field to Form (not timestamp)

Help
2007-01-02
2013-06-03
  • Tracy Shorrock

    Tracy Shorrock - 2007-01-02

    Hi,

    I am using the form to take bookings and need to add 'Start Date' and 'End Date' fields. I'd like these to be drop down choices (like when booking flights etc on travel sites), with the current day as the selected option.

    The data is submitted to a MySQL DB and via e-mail. I have two fields set up in the DB- 'startdate' and 'enddate', and they are both of type 'date' (although this can be changed if necessary).

    The closest thing I've found to what I want is:

    <select name="day"><?php
      for ($i = 1; $i <= 31; $i++) {
       echo "<option value=\&quot;$i\&quot;>$i</option>\n";
      }
    ?></select>
    <select name="month"><?php
      for ($i = 1; $i <= 12; $i++) {
       $monthname = date(‘F‘, mktime(12, 0, 0, $i, 1,
         2005));
       echo "<option value=\&quot;$i\&quot;>$monthname</option>";
      }
    ?></select>
    <select name="year"><?php
      for ($i = 2005; $i <= 2010; $i++) {
       echo "<option value=\&quot;$i\&quot;>$i</option>";
      }
    ?></select>

     
    • Tracy Shorrock

      Tracy Shorrock - 2007-01-02

      ... and here's the rest of the message!

      However, as you'll see this gives three variables (day, month, year) - and I just need one 'date'  variable to go into the 'startdate' and 'enddate' fields in the process.php form.

      I only know basic PHP and know that I will need to use an array to capture the day, month, year and make it into one 'date' variable that can be entered into the MySQL date field, but I'm unsure of how to get this done in the process.php file.

      I hope this makes sense. If someone has added date fields to their form I would really appreciate knowing how you achieved it.

      Any help appreciated.

      Cheers, and Happy New Year!

      Tracy

       
    • Musawir Ali

      Musawir Ali - 2007-01-03

      The way you are collecting the date information requires some post processing for it to be stored in the database's date format. However, unless you are doing some sort of calculation that involves the date, I don't see any reason for using the date data type in the database. You can simply store the date as a character string, in which case you will simply append the three variables that you obtain to create on strging which can then be stored in the db.

       
    • Musawir Ali

      Musawir Ali - 2007-01-03

      also forgot to mention that the new version of phpFormGenerator (v3.0) will have a date field type which will present the user with a nice little calendar interface. hopefully that will help.

       

Log in to post a comment.

Want the latest updates on software, tech news, and AI?
Get latest updates about software, tech news, and AI from SourceForge directly in your inbox once a month.