Check date and close form after specific date

How to automatically close a form after a specific expiration date.

Overview

The form needs to check the current date against a set expiration date to determine if it should be displayed.
Use an Event Switcher action in the form's On Load event with custom code to compare dates. If the current date is past the expiration date, trigger a closed event to redirect users and display a closure message.

Answered
Kw Kwalitijd 04 Apr, 2015
Hi, I would like to check the current date before showing a form. The form should expire on a specific date and show an notification like 'Subscription closed'. Can this be done?
Thanks in advance!
Gr GreyHead 04 Apr, 2015
Answer
1 Likes
Hi Kwalitijd,

Yes, you can do this. Add an Event Switcher from the Validation Actions group in the beginning of the form On Load event. Open the settings and, in the Events box replace success,fail with closed. Save and Close the Event Switcher, re-open it and click the Load Events button. When you Save and Close again you should now have just an On closed event.

In the Code box add something like this:
<?php
if  (time() > strtotime("05/15/2015 4:00PM") ) {
    return 'closed';
}
?>

Then in the On Closed box you can redirect to a different page with a message. Here's one way of doing that with another Custom Code action:
<?php
$app = JFactory::getApplication();
$app->enqueueMessage('Sorry, we&squo;re closed');
$app->redirect('index.php');
?>

Bob
This topic is locked and no more replies can be posted.