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 benedict - October 14, 2013

Thanks Gerry, that plugin did the trick instantly. Appreciate the explanation.