Page 1 of 1

Disable page only durring time period

Posted: Wed Oct 22, 2025 4:53 pm
by cwlutterloh
I have a forms page and the user wants one of the forms to only be avaiable during morning hours. I know how to manually disable the page but can I have it automatically disable during specfic time periods?

Re: Disable page only durring time period

Posted: Wed Oct 22, 2025 5:11 pm
by BaconFries
can I have it automatically disable during specfic time periods?
Yes it can be done but will require the use of a script such as javascript. The downside of this that anyone in the know could easily bypass by disabling javascript or viewing the page source. To avoid submission you would also need implement server-sided validation so to reject submissions during the set time frame.

Re: Disable page only durring time period

Posted: Wed Oct 22, 2025 5:26 pm
by jerryco
In case there will be no free alternatives offered in this thread, I use the paid software called MachForm and it shows this...

Image

Info on https://machform.com.

Re: Disable page only durring time period

Posted: Wed Oct 22, 2025 6:16 pm
by cwlutterloh
BaconFries wrote: Wed Oct 22, 2025 5:11 pm Yes it can be done but will require the use of a script such as javascript. The downside of this that anyone in the know could easily bypass by disabling javascript or viewing the page source. To avoid submission you would also need implement server-sided validation so to reject submissions during the set time frame.
This is for an internal Intranet site, my end users are not that savy. Can you elaborate on the script?

Re: Disable page only durring time period

Posted: Wed Oct 22, 2025 9:07 pm
by pmacdonald
if your page is PHP, the AI overload suggests this bit of code embedded at the top of the page, modify to your needs.

<?php
// Set your desired time zone. Find a list of supported time zones at php.net/manual/en/timezones.php.
date_default_timezone_set('America/New_York');

// Get the current hour in 24-hour format (0-23).
$current_hour = date('G');

// Define the time boundaries for redirection.
$early_boundary = 5; // 5am
$late_boundary = 12; // 12pm (noon)

// Check if the current time is earlier than 5am OR later than 12pm.
if ($current_hour < $early_boundary || $current_hour >= $late_boundary) {
// Specify the page to redirect to.
$redirect_url = 'https://www.example.com/unavailable.php';

// Redirect the user.
header('Location: ' . $redirect_url);
exit(); // Always exit after a header redirect.
}

// The rest of your page's code continues here if the time is within the allowed window.
// ...
?>

<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title>Open for Business</title>
</head>
<body>
<h1>Welcome! We are open for business.</h1>
<p>This page is only accessible between 5am and 12pm.</p>
</body>
</html>

Re: Disable page only durring time period

Posted: Thu Oct 23, 2025 4:05 am
by wwonderfull
A browser is time conscious only when it is open and the page is current active and loaded Infront of you, and it is also bound to system time settings. Server can have its own configuration. Now that said you wanted a specific form to appear disappear on a specific time that means if you wanted to dynamically change the form on the same page you would need asynchronous form generation for it.

Think it like this you are watching the clock and it is 5 second before it becomes morning, now 5 second past the page is still the same and the form is still the same unless with time event the browser asynchronously sends the event trigger to server to load the new form but if you relied only on the server than only the page reload or POST request would change the form or else it won't change.

So, the same solution in 2 ways even if custom.

Now logically speaking you will not be able to use same <form id="contactform-or-anyform"> to be reused by other form elements because it would cause conflicts. That means you would have to have a separate form dynamically generated so both form data are separate yet both forms are found in same place in different times.

Re: Disable page only durring time period

Posted: Thu Oct 23, 2025 8:06 pm
by cwlutterloh
I inserted this at the begining of the page but the button click shows 404 error...
-----------------
<?php
date_default_timezone_set('America/New_York');

$current_hour = date('G');

$early_boundary = 7:30;
$late_boundary = 10;

if ($current_hour < $early_boundary || $current_hour >= $late_boundary) {
$redirect_url = 'http://URL_NA';

header('Location: ' . $redirect_url);
exit();
}
?>
------------------

Re: Disable page only durring time period

Posted: Fri Oct 24, 2025 1:05 pm
by pmacdonald
I suspect the 404 error is due to the fact that the referenced page does not exist on your server:

'http://URL_NA';

Also, I don't think the existing code will work as expected if you are looking to do this based on a half hour setting, i.e. 7:30, actually I'm surprised you didn't get an error with that code.

$current_hour = date('G'); returns the hour as 0 to 23 only

additional code would be required to check for anything other than on the hour.

Re: Disable page only durring time period

Posted: Fri Oct 24, 2025 2:50 pm
by BaconFries
You can try the following using javascript rather that php. Add to your page with the form using Page HTML Between the <body></body> tags*. You will also need to change where it reads your form Id to match that of your Forms ID.
Note if the user/client has javascript disabled then this wont work.

Code: Select all

<script>
    const now = new Date(); 
    const currentMinutes = now.getHours() * 60 + now.getMinutes();

    const startMinutes = 7 * 60 + 30;  // 7:30 AM
    const endMinutes = 10 * 60;        // 10:00 AM

    if (currentMinutes >= startMinutes && currentMinutes < endMinutes) {
      document.getElementById('your form Id').classList.add('hidden');
    }
</script>

Re: Disable page only durring time period

Posted: Fri Oct 24, 2025 2:53 pm
by cwlutterloh
changing the time to "7" worked.

I just put in a dummy URL for this post.

Re: Disable page only durring time period

Posted: Sat Oct 25, 2025 2:10 pm
by MojoBoogie
Thanks for the heads up on MachForm. We are going to use their service.

Re: Disable page only durring time period

Posted: Sat Oct 25, 2025 4:59 pm
by jerryco
You're welcome!