需要单击php提交按钮两次

时间:2017-12-04 10:07:08

标签: javascript php jquery html

我尝试了一些不同的东西,只需按一次提交按钮来显示数据,这都是通过php(表单提交)完成的。 我尝试添加(ajaxSubmit,提交javascript),但我无法让它工作。

这是我的代码:

JS / jquery:

$.datepicker.setDefaults({
  showOn: "button",
  buttonImage: "./images/calender.png",
  buttonText: "Date Picker",
  buttonImageOnly: true,
  dateFormat: 'yy-mm-dd',
  showAnim: "fadeIn",
  defaultDate: -1,
  yearRange: '2017:2030',
  minDate: new Date(2017, 11 - 1, 1),
  maxDate: '+10Y',
});
$(function() {
  $("#cal_from").datepicker();
  $("#cal_to").datepicker();
});

PHP:

if(!empty($_POST["search"]["cal_from"])) {         
    $cal_from = $_POST["search"]["cal_from"];
    list($fid,$fim,$fiy) = explode("-",$cal_from);
    $_SESSION['fromdate'] = $cal_from;

    $cal_to = date('Y-m-d');
    if(!empty($_POST["search"]["cal_to"])) {
       $cal_to = $_POST["search"]["cal_to"];
       list($tid,$tim,$tiy) = explode("-",$_POST["search"]["cal_to"]);
       $post_at_todate = "$tiy-$tim-$tid";
       $_SESSION['todate'] = $cal_to;
    }
}

HTML:

<div class='col-md-6'>
  <div align='center' class='pull-right calender'>
      <form name='frmSearch' method='post' action=''>
          <p class='search_input'>
             <input type='text' placeholder='From Date' id='cal_from' name='search[cal_from]'  value='" . $cal_from . "' class='input-control' />
             <input type='text' placeholder='To Date' id='cal_to' name='search[cal_to]' style='margin-left:10px'  value='" . $cal_to . "' class='input-control' />           
             <input type='submit' name='go' value='Submit' >
         </p>
     </form>
 </div>
</div>

0 个答案:

没有答案