Default date showing even though no entry made in CMSB

3 posts by 2 authors in: Forums > CMS Builder
Last Post: October 14, 2013   (RSS)

By benedict - October 13, 2013

Hi guys,

I am having an issue with an events page with a form I am producing. For every event, the client wanted the ability to add up to 10 event dates that a person can choose to attend. Some events have 4 dates, some more. So in CMSB, I just created 10 fields - Event Date 1, Event Date 2, etc...

In my viewer page I have coded the 10 event date fields into a select field, coding it so that it should only show an event date if an entry has been made. In this example event (http://hrlegal.stockstreetserver.com/events-detail.php?Protecting-Your-Business-from-Ex-Employees-5) it correctly shows the first 4 event dates that have been entered, but then shows a default date for the other 6 dates that have not been entered in CMSB.

This is my select field code:

<label for="fieldEmail">Date You Wish To Attend:</label>
        <select name="date" id="date">
<option value="" selected="selected">--Please Select--</option>
            <?php if ($eventsRecord['1st_date_time']): ?>
<option value="<?php echo date("D, M jS, Y g:i a", strtotime($eventsRecord['1st_date_time'])) ?>"><?php echo date("D, M jS, Y g:i a", strtotime($eventsRecord['1st_date_time'])) ?></option>
          <?php endif ?>
          <?php if ($eventsRecord['2nd_date_time']): ?>
<option value="<?php echo date("D, M jS, Y g:i a", strtotime($eventsRecord['2nd_date_time'])) ?>"><?php echo date("D, M jS, Y g:i a", strtotime($eventsRecord['2nd_date_time'])) ?></option>
          <?php endif ?>
          <?php if ($eventsRecord['3rd_date_time']): ?>
<option value="<?php echo date("D, M jS, Y g:i a", strtotime($eventsRecord['3rd_date_time'])) ?>"><?php echo date("D, M jS, Y g:i a", strtotime($eventsRecord['3rd_date_time'])) ?></option>
          <?php endif ?>
          <?php if ($eventsRecord['4th_date_time']): ?>
<option value="<?php echo date("D, M jS, Y g:i a", strtotime($eventsRecord['4th_date_time'])) ?>"><?php echo date("D, M jS, Y g:i a", strtotime($eventsRecord['4th_date_time'])) ?></option>
          <?php endif ?>
          <?php if ($eventsRecord['5th_date_time']): ?>
<option value="<?php echo date("D, M jS, Y g:i a", strtotime($eventsRecord['5th_date_time'])) ?>"><?php echo date("D, M jS, Y g:i a", strtotime($eventsRecord['5th_date_time'])) ?></option>
          <?php endif ?>
          <?php if ($eventsRecord['6th_date_time']): ?>
<option value="<?php echo date("D, M jS, Y g:i a", strtotime($eventsRecord['6th_date_time'])) ?>"><?php echo date("D, M jS, Y g:i a", strtotime($eventsRecord['6th_date_time'])) ?></option>
          <?php endif ?>
          <?php if ($eventsRecord['7th_date_time']): ?>
<option value="<?php echo date("D, M jS, Y g:i a", strtotime($eventsRecord['7th_date_time'])) ?>"><?php echo date("D, M jS, Y g:i a", strtotime($eventsRecord['7th_date_time'])) ?></option>
          <?php endif ?>
          <?php if ($eventsRecord['8th_date_time']): ?>
<option value="<?php echo date("D, M jS, Y g:i a", strtotime($eventsRecord['8th_date_time'])) ?>"><?php echo date("D, M jS, Y g:i a", strtotime($eventsRecord['8th_date_time'])) ?></option>
          <?php endif ?>
          <?php if ($eventsRecord['9th_date_time']): ?>
<option value="<?php echo date("D, M jS, Y g:i a", strtotime($eventsRecord['9th_date_time'])) ?>"><?php echo date("D, M jS, Y g:i a", strtotime($eventsRecord['9th_date_time'])) ?></option>
          <?php endif ?>
          <?php if ($eventsRecord['10th_date_time']): ?>
<option value="<?php echo date("D, M jS, Y g:i a", strtotime($eventsRecord['10th_date_time'])) ?>"><?php echo date("D, M jS, Y g:i a", strtotime($eventsRecord['10th_date_time'])) ?></option>
          <?php endif ?>
                  </select>

How do I make fields with no date entry not appear in this list?

Thanks in advance.

By gkornbluth - October 14, 2013

Hi Benedict,

Here's an excerpt from a recipe in my CMSB Cookbook http://www.thecmsbcookbook.com that might help.

If you try to test for a blank date with a simple:

_____ code ________________________________________________

<?php if ($your_tableRecord['your_date_field']): ?>

__________________________________________________________

The test won’t work as you expect, since there is actually a date value stored in your database, (0000-00-00 00:00:00)

Until this glitch is fixed, and you update to the “fixed” version, you’ll have to format your test like this:

_____ code ________________________________________________

<?php if ($your_tableRecord['your_date_field'] && $your_tableRecord['your_date_field'] != '0000-00-00 00:00:00'): ?>

__________________________________________________________

You can learn more about date formatting at:

http://www.php.net/date

You might also try the free plugin attached that Dave Edis created a long time ago.

Hope that helps,

Jerry Kornbluth


The first CMS Builder reference book is now available on-line!







Take advantage of a free 3 month trial subscription, only for CMSB users, at: http://www.thecmsbcookbook.com/trial.php