2014-04-03 10:02

如何在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">
        <input type="text" name="x_date_from" id="input_from" data-value="<?=$_REQUEST['x_date_from'];?>">
        <input type="text" name="x_date_to" id="input_to" data-value="<?=$_REQUEST['x_date_to'];?>">

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>
  • 点赞
  • 写回答
  • 关注问题
  • 收藏
  • 复制链接分享
  • 邀请回答


  • doudou521125 doudou521125 7年前

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

        <?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']; ?>]);
    点赞 评论 复制链接分享