dtczp02204 2013-05-13 22:39
浏览 15

检查时间以允许在PHP(和javascript)中填写表单

For a website, we have a form where a client enters in their ID number that sends them to a new page that allows them to make a request for our services.

We want to change it so that clients can only request our services from Tuesday-Friday from 12pm - 4pm. If they try to enter their id number during a time outside of Tuesday-Friday from 12pm - 4pm, it will tell them they cannot request our services.

What I want to do is that if the user accesses the page during times when they cannot make a request, an alert box (through javascript) will pop up telling them that. I also want to code something so that if they try to progres forward (clicking the create request button), they will not (though php).

I'm not sure how to check these times with PHP and Javascript in order to accomplish this. If anyone has any insight in how to do this, that would be fantastic. Thanks!

  • 写回答

1条回答 默认 最新

  • dongshou6041 2013-05-13 22:47
    关注

    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 only available Tuesday - Friday, 12:00pm to 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

    评论

报告相同问题?

悬赏问题

  • ¥60 求一个简单的网页(标签-安全|关键词-上传)
  • ¥35 lstm时间序列共享单车预测,loss值优化,参数优化算法
  • ¥15 基于卷积神经网络的声纹识别
  • ¥15 Python中的request,如何使用ssr节点,通过代理requests网页。本人在泰国,需要用大陆ip才能玩网页游戏,合法合规。
  • ¥100 为什么这个恒流源电路不能恒流?
  • ¥15 有偿求跨组件数据流路径图
  • ¥15 写一个方法checkPerson,入参实体类Person,出参布尔值
  • ¥15 我想咨询一下路面纹理三维点云数据处理的一些问题,上传的坐标文件里是怎么对无序点进行编号的,以及xy坐标在处理的时候是进行整体模型分片处理的吗
  • ¥15 CSAPPattacklab
  • ¥15 一直显示正在等待HID—ISP