Not letting me leave a date field blank

5 posts by 4 authors in: Forums > CMS Builder
Last Post: October 15, 2010   (RSS)

On the site I am working on there is a vacancies page.
It's all working but at the moment there are no vacancies and I want to leave the closing date field blank or at least 00/00/00 but there is not option for me to do this. Any ideas?

Re: [Kittybiccy] Not letting me leave a date field blank

By Dave - January 16, 2009

Hi Kittybiccy,

There's no way to do that currently.

Another solution might be to have a checkbox field for "no_vacancies" or "hide_date" and not show the date if that is checked with some code like this:

<?php if ($record['no_vacancies']): ?>
Sorry there are no vanancies
<?php else: ?>
... display date here ...
<?php endif ?>

Let me know if that will work for you.
Dave Edis - Senior Developer
interactivetools.com

Re: [Dave] Not letting me leave a date field blank

By Mikey - October 14, 2010

Dave,
I need to post events that have a begin and end date. Other events only have begin dates... with no end dates. I'd like to show the end dates for events, but if no end date is chosen for an event, there's still a date that shows up on the page (Event Ends: Wed, Dec 31st, 1969 7:00:00 pm)

Any suggestions how I can make an event without an end date not show this random date (Event Ends: Wed, Dec 31st, 1969 7:00:00 pm) an only show actual event end dates if they exist, otherwise no event end date is shown.

Also, any suggestions on how to make the Previous and Next buttons work in a weekly mode? I've messed around with that for a few hours and simply can't figure it out. Cheers and thanks for any help you can offer. Zickey

Here's the code I'm using:

BEGIN CODE ============================

</head>
<body>
<?php
$monthNames = Array("January", "February", "March", "April", "May", "June", "July", "August", "September", "October", "November", "December");
if (!isset($_REQUEST["month"])) $_REQUEST["month"] = date("n");
if (!isset($_REQUEST["year"])) $_REQUEST["year"] = date("Y");

$cMonth = $_REQUEST["month"];
$cYear = $_REQUEST["year"];

$prev_year = $cYear;
$next_year = $cYear;

$prev_month = $cMonth-1;
$next_month = $cMonth+1;

if ($prev_month == 0 ) {
$prev_month = 12;
$prev_year = $cYear - 1;
}
if ($next_month == 13 ) {
$next_month = 1;
$next_year = $cYear + 1;
}

// date range
list($eventsRecords, $eventsMetaData) = getRecords(array(
'tableName' => 'events',
'where' => '(NOW() + INTERVAL 6 DAY) >= date and date >= TIMESTAMP(CURDATE(), "00:00:00")',
'orderBy' => 'date',
));

// organize events into an array indexed by 'day', each element being a list of events on that day
$eventsByDay = array();
foreach ($eventsRecords as $event) {
$day = intval(date('d', strtotime($event['date'])));
if (!array_key_exists($day, $eventsByDay)) { $eventsByDay[$day] = array(); }
$eventsByDay[$day][] = $event;
}

?>

<p><a href="<?php echo $_SERVER["PHP_SELF"] . "?month=". $prev_month . "&year=" . $prev_year; ?>" class="PreviousButton">Previous</a></p>
<p><a href="<?php echo $_SERVER["PHP_SELF"] . "?month=". $next_month . "&year=" . $next_year; ?>" class="NextButton">Next</a></p>

<?php $lastDate = ""; ?>
<?php foreach($eventsRecords as $record):
$showDate = false;
$formatted_date = date("l, M jS", strtotime($record['date'])); // Add a ,Y to display the year as well. Change M to F for full month's name
if ($formatted_date != $lastDate):
$lastDate = $formatted_date;
$showDate = true;
endif; ?>

<?php if ($showDate): ?>
<?php echo $formatted_date; ?></div>
<?php endif ?>

<h3><a href="<?php echo $record['_link'] ?>"><?php echo $record['title'] ?></a></h3>
<h4>Time: <?php echo date("D, M jS, Y g:i:s a", strtotime($record['date'])) ?></h4>

<?php if ($record['end_date']): ?>
<h4>Event Ends: <?php echo date("D, M jS, Y g:i:s a", strtotime($record['end_date'])) ?></h4>
<?php endif ?>

<p><?php echo $record['content'] ?></p>

<?php endforeach ?>
</body>
</html>

END CODE ============================

Re: [zickey] Not letting me leave a date field blank

By Jason - October 15, 2010

Hi Zickey,

What could be happening is there is a zero value in your end_date field. Try this code:

<?php if ($record['end_date'] && $record['end_date']!=0): ?>
<h4>Event Ends: <?php echo date("D, M jS, Y g:i:s a", strtotime($record['end_date'])) ?></h4>
<?php endif ?>


If this doesn't work, try:
<?php showme($record['end_date']);?>
to output exactly what value is being stored in end_date.

Hope this helps.
---------------------------------------------------
Jason Sauchuk - Project Manager
interactivetools.com

Hire me! Save time by getting our experts to help with your project.
http://www.interactivetools.com/consulting/