Checking Time to allow form filling in PHP (and javascript) -


for website, have form client enters in id number sends them new page allows them make request our services.

we want change clients can request our services tuesday-friday 12pm - 4pm. if try enter id number during time outside of tuesday-friday 12pm - 4pm, tell them cannot request our services.

what want if user accesses page during times when cannot make request, alert box (through javascript) pop telling them that. want code if try progres forward (clicking create request button), not (though php).

i'm not sure how check these times php , javascript in order accomplish this. if has insight in how this, fantastic. thanks!

this should work:

<?php $dayofweek = date("w"); $currenthour = date("g");  if ($dayofweek >= 2 && $dayofweek <= 5 && $currenthour >= 12 && $currenthour <= 16) {   // show form } else {     ?>     <script>alert('form available tuesday - friday, 12:00pm 4:00pm');</script>     <?php } ?> 

for more information on php's date function, see: http://us1.php.net/manual/en/function.date.php

"g" = 24 hour format without leading 0's

"w" = day of week, 0 = sunday, 6 = saturday


Comments

Popular posts from this blog

c# - DetailsView in ASP.Net - How to add another column on the side/add a control in each row? -

javascript - firefox memory leak -

Trying to import CSV file to a SQL Server database using asp.net and c# - can't find what I'm missing -