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
Code Help: Removing content based on date/time
Moderator: General Moderators
As for detecting the date server side: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.
Code: Select all
$today = getdate();Code: Select all
var today = new Date();Code: Select all
<input type="hidden" name="serverTime" value="$today">http://www.phpbuilder.com/manual/function.getdate.php
http://www.comptechdoc.org/independent/ ... adate.html
That might not be helpful if the client is in a different timezone.SpecialK wrote:My suggestion is to include the PHP date in a hidden varible so that you can use JavaScript to detect it.
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.
Real programmers don't comment their code. If it was hard to write, it should be hard to understand.
Why client-side time...
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
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
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.
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