蛋糕PHP日期验证

时间:2014-05-04 09:29:28

标签: javascript jquery cakephp datepicker

我有以下代码,允许用户添加订单详细信息。我正在使用datapicker jQuery显示日期日历。例如,订单日期字段,我想阻止用户选择将来的日期。我怎样才能做到这一点? 我的代码如下: edit.ctp:

<html lang="en">
    <head>
        <meta charset="utf-8">
        <title>jQuery UI Datepicker - Default functionality</title>
        <link rel="stylesheet" href="//code.jquery.com/ui/1.10.4/themes/smoothness/jquery-ui.css">
        <script src="//code.jquery.com/jquery-1.10.2.js"></script>
        <script src="//code.jquery.com/ui/1.10.4/jquery-ui.js"></script>
        <link rel="stylesheet" href="/resources/demos/style.css">
        <script>
            $(function() {
                $("#datepicker").datepicker({
                    changeMonth: true,
                    changeYear: true,
                    yearRange: '1950:2020',
                    dateFormat: "yy-mm-dd"
                });

                $("#datepicker2").datepicker({
                    changeMonth: true,
                    changeYear: true,
                    yearRange: '1950:2020',
                    dateFormat: "yy-mm-dd"
                });

            });
        </script>
    </head>
    <?php
    $usertype = $this->SESSION->read('User.usertype');
    ?>
    <body>
        <div class="orders form">
            <?php echo $this->Form->create('Order'); ?>
            <fieldset>
                <legend><?php echo __('Edit Order Details'); ?></legend>
                <?php
                echo $this->Form->input('id');
                echo $this->Form->input('invoice_number', array('required' => false));
                echo $this->Form->input('order_date', array('required' => false, 'id' => 'datepicker', 'type' => 'text'));
                echo $this->Form->input('payment_type', array('required' => false, 'options' => array('Cash' => 'Cash', 'EFTPOS' => 'EFTPOS', 'CC' => 'CC', 'Cheque' => 'Cheque', 'PayPal' => 'PayPal'), 'empty' => '(choose one)'));
                echo $this->Form->input('order_type', array('required' => false, 'options' => array('Email' => 'Email', 'Telephone' => 'Telephone', 'Web' => 'Web'), 'empty' => '(choose one)'));
                echo $this->Form->input('date_promised', array('required' => false, 'id' => 'datepicker2', 'type' => 'text'));
                echo $this->Form->input('order_description', array('required' => false));
                echo $this->Form->input('order_comments', array('required' => false));
                echo $this->Form->input('order_total', array('required' => false));
                echo $this->Form->input('amount_deposited', array('required' => false));
                echo $this->Form->input('balance_due', array('required' => false));

                /* echo $this->Form->input('customers_id', array('required'=>false));
                  echo $this->Form->input('employees_id', array('required'=>false));
                 */
                echo $this->Form->input('customers_id', array('label' => 'Customer Name', 'options' => $customers, 'label' => 'Customer Name', 'required' => false));
                echo $this->Form->input('employees_id', array('label' => 'Employee name', 'options' => $employees, 'label' => 'Employee name', 'required' => false));
                ?>
            </fieldset>
            <?php echo $this->Form->end(__('Submit')); ?>
        </div
    </body>
</html>

有人可以帮忙吗?

2 个答案:

答案 0 :(得分:0)

试试这个

$(function() { $("#datepicker").datepicker({  
      maxDate: '0'}); 
});

这会将maxDate设置为当前日期(即今天)的+0天。 Here是参考

答案 1 :(得分:0)

<强>小提琴: http://jsfiddle.net/pvXzb/

<强> jquery的:

 $("#datepicker").datepicker({
     changeMonth: true,
     changeYear: true,
     yearRange: '1950:2020',
     dateFormat: "yy-mm-dd",
     maxDate: 0
});