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>

图片转代码服务由CSDN问答提供 功能建议

我正在使用codeigniter和doctrine.php而且我被困在这个地方,当时我没有选择任何值 从datepicker它应该在数据库中提交null值,但它每次都发送昨天的日期。</ p>

  function initDatePicker(datePickerID,dateInput){
 $(“#”+ datePickerID)  
 
 //初始化datepicker 
 .datepicker()
 
 //检测更改日期事件
 .on('changeDate',function(data){
 var date = new Date(data)  .date); 
 var dateString = date.getDate()+' - '+ parseInt(date.getMonth()+ 1)+' - '+ date.getFullYear(); 
 $(“#”+ dateInput)  .val(dateString); 
}); 
} 
 </ code> </ pre> 
 
 

控制器</ p>

  $ salesOrder-&gt  ; setDateOfBilling($ post_data ['date_of_billing']); 
 if($ date_of_billing)
 {
 $ salesOrder-&gt; setBillingStatus(“付费”); 
} 
else 
 {
 $ salesOrder-&gt  ; setBillingStatus(“Not Paid”); 
} 
 $ salesOrder-&gt; setDateOfPayment($ post_da  ta ['date_of_payment']); 
 
 $ em-&gt; persist($ salesOrder); 
 $ em-&gt; flush(); 
 </ code> </ pre> 
 
 

模型</ p>

  / ** 
 * @Column(type =“datetime”,nullable = true)
 * / 
 nprotected $ date_of_billing; 
 
公共函数getDateOfBilling  ()
 {
返回$ this-&gt; date_of_billing; 
} 
 
公共函数setDateOfBilling($ date_of_billing)
 {
 $ this-&gt; date_of_billing = new \ DateTime($ date_of_billing); 
  } 
 </ code> </ pre> 
 
 

查看 这是我使用日期选择器的表单</ p>

 &lt; div class =“form  -group“&gt; 
&lt; label class =”col-sm-4 control-label“&gt;结算日期&lt; / label&gt; 
&lt; div class =”col-sm-5“&gt; 
&lt;输入 type =“text”name =“date_of_billing”id =“date_of_billing”class =“form-control”placeholder =“Billing of Date”
 
 readonly&gt; 
&lt; div id =“billing_date_picker”&gt;&lt; /  div&gt; 
&lt; / div&gt; 
 </ code> </ pre> 
 
 

</ p> </ div>

2条回答 默认 最新

相关推荐 更多相似问题