doucha7329 2015-04-16 20:23
浏览 29
已采纳

在Twitter引导程序Datepicker中提交null值

I am using codeigniter and doctrine.php and I am stuck at this place where when I don't select any value from datepicker it should submit null value in database, but its sending yesterdays date everytime instead.

function initDatePicker(datePickerID, dateInput){
    $( "#" + datePickerID )

    // Initializing the datepicker
    .datepicker()

    // Detecting the on change date event
    .on('changeDate', function (data) {
      var date = new Date(data.date);
      var dateString = date.getDate() + '-' + parseInt(date.getMonth() + 1) + '-' + date.getFullYear();
      $("#" + dateInput).val(dateString);
    });
}

Controller

 $salesOrder->setDateOfBilling($post_data['date_of_billing']);
  if($date_of_billing)
  {
  $salesOrder->setBillingStatus("Paid");
}
else
{
  $salesOrder->setBillingStatus("Not Paid");
}
  $salesOrder->setDateOfPayment($post_data['date_of_payment']);

  $em->persist($salesOrder);
  $em->flush();

Model

/**
 * @Column(type="datetime", nullable=true)
 */
protected $date_of_billing;

public function getDateOfBilling()
{
    return $this->date_of_billing;
}

public function setDateOfBilling($date_of_billing)
{
    $this->date_of_billing = new \DateTime($date_of_billing);
}

View This is the form where I use date picker

<div class="form-group">
<label class="col-sm-4 control-label">Date of Billing</label>
<div class="col-sm-5">
  <input type="text" name="date_of_billing" id="date_of_billing" class="form-control" placeholder="Date Of Billing" 

  readonly>
  <div id="billing_date_picker"></div>
</div>

  • 写回答

2条回答 默认 最新

  • dongpi3237 2015-04-17 21:08
    关注

    Got the answer.did changes in the controller and model for above code and its working...

    Controller

    $billing_date = $post_data['date_of_billing'] === "" ? null : $post_data['date_of_billing'];
      echo $billing_date;
      $salesOrder->setDateOfBilling($post_data['date_of_billing']);
    
      $salesOrder->setBillingStatus("Paid");
    

    Model

    public function setDateOfBilling($date_of_billing)
    {
        if ($date_of_billing == null) {
            $this->date_of_billing = null;
        } else {
            $this->date_of_billing = new \DateTime($date_of_billing);    
        }
    }
    
    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论
查看更多回答(1条)

报告相同问题?

悬赏问题

  • ¥15 如何用Labview在myRIO上做LCD显示?(语言-开发语言)
  • ¥15 Vue3地图和异步函数使用
  • ¥15 C++ yoloV5改写遇到的问题
  • ¥20 win11修改中文用户名路径
  • ¥15 win2012磁盘空间不足,c盘正常,d盘无法写入
  • ¥15 用土力学知识进行土坡稳定性分析与挡土墙设计
  • ¥70 PlayWright在Java上连接CDP关联本地Chrome启动失败,貌似是Windows端口转发问题
  • ¥15 帮我写一个c++工程
  • ¥30 Eclipse官网打不开,官网首页进不去,显示无法访问此页面,求解决方法
  • ¥15 关于smbclient 库的使用