Page 1 of 1
Code Help: Removing content based on date/time
Posted: Mon Sep 25, 2006 10:07 am
by TKramer
I have searched the forum looking for what I need but cannot find a complete solution, so I apologize in advance if this has been answered elsewhere...
I cannot figure out how to do the following, any help would be appreciated. I have recently picked up PHP and struggle sometimes.
I have a form on my page that I need to remove an "option" from a "select" element based on the date and time. The form is used to make reservations, and the e-mails that are sent from the form are not monitored after 4:30 p.m. on the date of the event.
So, I am in need of code that will a) detect the date; b) detect the time on the browser-side, not server-side, and; c) display/not display the option tag based on that information.
Thank you in advance,
Kramer
Posted: Mon Sep 25, 2006 11:25 am
by onion2k
Moved to clientside.
Posted: Mon Sep 25, 2006 2:07 pm
by SpecialK
So, I am in need of code that will a) detect the date; b) detect the time on the browser-side, not server-side, and; c) display/not display the option tag based on that information.
As for detecting the date server side:
For detecting it client side
My suggestion is to include the PHP date in a hidden varible so that you can use JavaScript to detect it.
Code: Select all
<input type="hidden" name="serverTime" value="$today">
You can find the full options on the PHP date and JavaScript date at the following sites
http://www.phpbuilder.com/manual/function.getdate.php
http://www.comptechdoc.org/independent/ ... adate.html
Posted: Mon Sep 25, 2006 4:20 pm
by pickle
SpecialK wrote:My suggestion is to include the PHP date in a hidden varible so that you can use JavaScript to detect it.
That might not be helpful if the client is in a different timezone.
I'm curious as to the reason why you want to check the time client side as opposed to server side? You said the email isn't checked after 4:30pm - I assume that's your time & not client time.
However, it's always before 4:30 pm somewhere in the world - so if you check the client side time, there'll be no server time that isn't after 4:30 on at least one computer in cyberspace.
Why client-side time...
Posted: Tue Sep 26, 2006 9:49 am
by TKramer
The event that they will be reserving tickets for will be 99.9% local patrons (local to the event) and in the same time zone that the event is in.
The server time is not local.
We are trying to prevent them from trying to reserve tickets just prior to the event and the administration not seeing the online reservation request.
I hope this makes sense. I just spent another chunk of time searching the web and not finding a complete answer.
- Kramer
Posted: Tue Sep 26, 2006 10:01 am
by SpecialK
It seems that this doesn't require anything from the client time.
You will have to compare it to an event time, which I assume is stored in a DB. If a user turns off JS then the whole client side is broken and won't prevent them from making the request. You will still need a server side check to ensure of this. The javascript will do the same thing without a post/get but shouldn't be used as 100% error checking.
You know when the event is, you know the server time. You can easily set a restriction based on the time difference from your local server time to the event time (which can be set to any timezone you desire) and return a message to the user that it's too late to reserve tickets for the event.
- get the time from the DB
get the current time
use math to compare the times