Tassos Marinos Developer of Joomla Extensions

How to Allow Form Submissions in Specific Date Range

Published in Convert Forms
Updated 05 Nov, 2020
Heads up! This article contains PHP code and is intended for developers. We offer this code as a courtesy, but don't provide support for code customizations or 3rd party development.

Would you like to collect submittions between specific dates? This is quite useful when you have an event planned out and you want to start collecting submissions days before the event and stop a day before the event starts. The following PHP snippet will provide a helpful message to your users that missed the deadline.

Setup

Display a Validation Error During Form Submission

To display a message after your user has submitted the form, whether the date they submitted it is within the given date range (i.e. if they are within the deadline), copy the code shown below and place it into the PHP Scripts -> Form Process area of your form.

// Set start, end date as well as the error message when submission is done when not within range
$start_date = '2020-05-27 09:00';
$end_date = '2021-05-25 15:00';

// Enter message when submission is done outside the date range
$error = "Submission is available between {$start_date} and {$end_date}";

// Do not edit below
$now = date('Y-m-d H:i');

if ($now < $start_date || $now > $end_date) {
    throw new Exception($error);
}

Hide Form With a Warning Message

To display a message before your form, whether your users can submit the form (i.e. if they are within the deadline), copy the code shown below and place it into the PHP Scripts -> Form Display area of your form.

// Set start, end date as well as the error message when submission is done when not within range
$start_date = '2020-05-27 09:00';
$end_date = '2021-05-25 15:00';

// Enter message when submission is done outside the date range
$error = "Submission is available between {$start_date} and {$end_date}";

// Do not edit below
$now = date('Y-m-d H:i');

if ($now < $start_date || $now > $end_date) {
    $formLayout = $error;
}