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']; ?>]);
    
    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?

悬赏问题

  • ¥15 执行 virtuoso 命令后,界面没有,cadence 启动不起来
  • ¥50 comfyui下连接animatediff节点生成视频质量非常差的原因
  • ¥20 有关区间dp的问题求解
  • ¥15 多电路系统共用电源的串扰问题
  • ¥15 slam rangenet++配置
  • ¥15 有没有研究水声通信方面的帮我改俩matlab代码
  • ¥15 ubuntu子系统密码忘记
  • ¥15 保护模式-系统加载-段寄存器
  • ¥15 电脑桌面设定一个区域禁止鼠标操作
  • ¥15 求NPF226060磁芯的详细资料