dpchen2004 2014-04-03 10:02
浏览 30
已采纳

如何在PHP中使用$ _REQUEST将日期加载到pickadate中

I have an implementation of amsuls pickadate plugin . I have created the following form incorporating the pop up date picker:

Form, from and to input fields

When I choose a value for both of the pickdates, I want to be able to submit the form, but use the $_REQUEST['input_value_from'] and $_REQUEST['input_value_to'] values to load the dates back into the form. If the user for e.g. forgets to fill in another part of the form.

I had a look at the set method which is stated here

My current html is:

<div class="section__block section__block--scoped">
    From:
    <fieldset>
        <input type="text" name="x_date_from" id="input_from" data-value="<?=$_REQUEST['x_date_from'];?>">
    </fieldset>
    To:
    <fieldset>
        <input type="text" name="x_date_to" id="input_to" data-value="<?=$_REQUEST['x_date_to'];?>">
    </fieldset>
</div>

My current js is:

var $input_from = $('#input_from').pickadate();
var picker_from = $input_from.pickadate('picker');
picker_from.set('select', $('#input_from').attr("data-value"));

var $input_to = $('#input_to').pickadate();
var picker_to = $input_to.pickadate('picker');
picker_to.set('select', $('#input_to').attr("data-value"));

with the relevant pickadate scripts

<script src="/x/js/calendar/pickadate.js-3.4.0/lib/picker.js"></script>
<script src="/x/js/calendar/pickadate.js-3.4.0/lib/picker.date.js"></script>
<script src="/x/js/calendar/pickadate.js-3.4.0/lib/picker.time.js"></script>
<script src="/x/js/calendar/pickadate.js-3.4.0/lib/legacy.js"></script>
<script src="/x/js/calendar/pickadate.js-3.4.0/demo/scripts/main.js"></script>
  • 写回答

1条回答 默认 最新

  • doudou521125 2014-04-03 10:19
    关注

    When loading the page, you can pass the PHP variable to the initialize method of the pickadate() function.

    $('#input_from').pickadate({
        <?php echo "select: [" . $_REQUEST['input_value_from'] . "]";?> //Format[yyyy,m,d]
    })
    

    Format $_REQUEST['input_value_from'] in the form of yyyy,m,d.

    Final code used was:

    a function:

    $from_split = getYearMonthDayFromDate($_REQUEST['x_date_from']);
    

    then adjusted the js to look like this:

    var $input_from = $('#input_from').pickadate();
    var picker_from = $input_from.pickadate('picker');
    picker_from.set('select', [<?php echo $from_split['year'].','.$from_split['month'].','.$from_split['day']; ?>]);
    
    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?

悬赏问题

  • ¥20 基于MSP430f5529的MPU6050驱动,求出欧拉角
  • ¥20 Java-Oj-桌布的计算
  • ¥15 powerbuilder中的datawindow数据整合到新的DataWindow
  • ¥20 有人知道这种图怎么画吗?
  • ¥15 pyqt6如何引用qrc文件加载里面的的资源
  • ¥15 安卓JNI项目使用lua上的问题
  • ¥20 RL+GNN解决人员排班问题时梯度消失
  • ¥60 要数控稳压电源测试数据
  • ¥15 能帮我写下这个编程吗
  • ¥15 ikuai客户端l2tp协议链接报终止15信号和无法将p.p.p6转换为我的l2tp线路