doucha7329
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
    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);    
        }
    }
    
    点赞 评论
  • duan6832168
    duan6832168 2015-04-16 23:31

    May be problem here " $( "#" + datePickerID )"

    Try this:

    var dpid = "#" + datePickerID;
    $(dpid).datepicker();
    
    点赞 评论

相关推荐