如何验证datepicker是否为空

时间:2014-10-06 12:57:49

标签: php

如何检查$dateStart$dateEnd是否为空?

<?php
if (isset($_POST['submit'])) {
       $leaveR = $_POST['leave'];
       $dateStart = $_POST['startDate'];
       $dateEnd = $_POST['endDate'];
       $leaveReason = $_POST['reason'];
       $credits = $_POST['credit'];
       $oic = $_POST['oicc'];
       if ($leaveR == "" || $dateStart == "" || $dateEnd == "" || $leaveReason == "" || 
           $credits == "" || $oic == "") {
          echo '<div class="alert alert-danger" role="alert">Fill up all fields</div>';

1 个答案:

答案 0 :(得分:0)

这部分取决于您的JavaScript代码。 datepicker是默认设置为当前日期还是&#34; 0000-00-00&#34;例如。或者它只是返回空白。

不知道你的javascript启动datepicker的综合答案:

if( isset( $_POST['startDate'] ) && trim( $_POST['startDate'] ) !== "" && trim( $_POST['startDate'] ) !== "0000-00-00" || !isset( $_POST['startDate'] ) ) { 
    // do something
}