Php 使用Zebra Datepicker验证我的用户表单中的无效日期格式

Php 使用Zebra Datepicker验证我的用户表单中的无效日期格式,php,jquery,validation,datepicker,Php,Jquery,Validation,Datepicker,我已经在我的用户表单页面中添加了zebra datepicker代码 天气看起来很好: 表单上的错误图像 我给你这里的代码,可以检查一下,我的代码有什么问题 rest我的所有其他属性都工作正常,只是停留在日期格式:( 整个项目文件也上传到这里 下载:dropbox.com/s/wa5hnugwcn5s6ox/project.zip?dl=0 我也放置了一个代码,这是我面临的一个问题! 页面重命名:user.php private function set_date_of_birth($date

我已经在我的用户表单页面中添加了zebra datepicker代码

天气看起来很好:

表单上的错误图像

我给你这里的代码,可以检查一下,我的代码有什么问题

rest我的所有其他属性都工作正常,只是停留在日期格式:( 整个项目文件也上传到这里

下载:dropbox.com/s/wa5hnugwcn5s6ox/project.zip?dl=0 我也放置了一个代码,这是我面临的一个问题! 页面重命名:user.php

private function set_date_of_birth($date_of_birth) {
        $reg = "/^\d{2}\-\d{2}\-\d{4}$/";

        if(!preg_match($reg, $date_of_birth)){
            throw new Exception("Invalid Date Format");
        }

        $parts = explode("-", $date_of_birth);

        list($day, $month, $year) = $parts;

        if(!isset($day) || !isset($month) || !isset($year)){
            throw new Exception("Invalid/Date PArameters");
        }

        if(!checkdate($month, $day, $year)){
            throw new Exception("Invalid/Missing Date of Birth");
        }

        //$this->date_of_birth = mktime(0, 0, 0, $month, $day, $year);
        $this->date_of_birth = strtotime($date_of_birth);

    }

    private function get_day() {
        if(is_null($this->date_of_birth)){
            return 0;
        }
        $date = date("d", $this->date_of_birth);
        return $date;

    }

    private function get_month() {
        if(is_null($this->date_of_birth)){
            return 0;
        }
        $date = date("m", $this->date_of_birth);
        return $date;

    }
    private function get_year() {
        if(is_null($this->date_of_birth)){
            return 0;
        }
        $date = date("Y", $this->date_of_birth);
        return $date;

    }

    private function get_date_of_birth() {

        if(is_null($this->date_of_birth)){
            return "";
        }
        $date = date("d-m-Y", $this->date_of_birth);
        return $date;

    }
2) Singup.php

<div class="row">
        <div class="cell cell-left">Date Of Birth</div>
        <div class="cell cell-right">
            <input type="text" id="date_of_birth" name="date_of_birth" class="datepicker" placeholder="dd-mm-YYYY" value="<?php echo($obj_user->date_of_birth); ?>">
            <span id="dob_error">
                <?php
                if(isset($errors['date_of_birth'])){
                    echo($errors['date_of_birth']);
                }

                ?></span>
        </div>
        <div class="clear-box"></div>
    </div>

作为测试,我做了以下工作:

class zebra{

    public static function set_date_of_birth( $date_of_birth ) {
        try{
            $reg = "/^\d{2}\-\d{2}\-\d{4}$/";

            if(!preg_match($reg, $date_of_birth)){
                throw new Exception("Invalid Date Format");
            }
            $parts = explode("-", $date_of_birth);

            list($day, $month, $year) = $parts;
            if(!isset($day) || !isset($month) || !isset($year)){
                throw new Exception("Invalid/Date PArameters");
            }
            if(!checkdate($month, $day, $year)){
                throw new Exception("Invalid/Missing Date of Birth");
            }

            $date_of_birth = strtotime( $date_of_birth );

            return $date_of_birth;
        }catch( Exception $e ){
            return $e->getMessage();
        }
    }

}
echo zebra::set_date_of_birth('19-11-2015');
echo '<br />';
echo zebra::set_date_of_birth('19-11-15');
/* 
    and the output was:-
    1447891200
    Invalid Date Format 
*/
class斑马{
公共静态函数设置出生日期($date\u of\u birth){
试一试{
$reg=“/^\d{2}\-\d{2}\-\d{4}$/”;
如果(!preg_匹配($reg,$date_of_出生)){
抛出新异常(“无效日期格式”);
}
$parts=爆炸(“-”,$date\u of\u birth);
列表($day、$month、$year)=$parts;
如果(!isset($day)| |!isset($month)| |!isset($year)){
抛出新异常(“无效/日期参数”);
}
如果(!checkdate($month,$day,$year)){
抛出新异常(“无效/缺少出生日期”);
}
$date\u of_birth=strotime($date\u of_birth);
返回$出生日期;
}捕获(例外$e){
返回$e->getMessage();
}
}
}
echo zebra::设定出生日期(“2015年11月19日”);
回声“
”; 回声斑马::设定出生日期('19-11-15'); /* 结果是:- 1447891200 无效的日期格式 */
因此,该函数工作正常,但我看不出在您的代码中您在哪里调用函数
设置出生日期

谢谢大家


Extra
在提交表单时产生了一个问题,现在它已修复

我已经上传了它,您可以自己检查吗,我已经在user.php上添加了set_date_of_birth,在这里我已经设置了函数。。。我正在signup.php上调用函数,好吧——根据我更好的判断,我下载了zip文件并查看了一下,特别是您提到的两个特定文件。我在任何地方都看不到对您实际调用函数
set\u date\u of\u birth
的引用,尽管我可以看到对由上述函数/方法
set\u date\u of\u birth()设置的变量/属性(
date\u of\u birth
)的引用
~因此,除非在某处(处理用户输入时!)显式调用此函数,否则变量/属性将不可用。函数将调用私有函数set_date_of_birth($date_of_birth){,$date\u of_birth定义在user.php private memeber上…set\u date\u of_birth和get\u date\u of_birth设置在user.php中的
user.php
models
-我可以看到函数
set\u date\u of_birth
被定义但没有被调用/调用。echo”“;print\r($_POST);echo“”;我已经测试了我的表单,没有class=“datepicker”,POST中就有“date_of_birth”。将类添加回行时,JS会禁用输入。可能使用Zebra datepicker的人知道发生了什么。我不知道为什么它会禁用输入。
try {
    $obj_user->date_of_birth = $_POST['date_of_birth'] ;

} catch (Exception $ex) {
    $errors['date_of_birth'] = $ex->getMessage();

}
class zebra{

    public static function set_date_of_birth( $date_of_birth ) {
        try{
            $reg = "/^\d{2}\-\d{2}\-\d{4}$/";

            if(!preg_match($reg, $date_of_birth)){
                throw new Exception("Invalid Date Format");
            }
            $parts = explode("-", $date_of_birth);

            list($day, $month, $year) = $parts;
            if(!isset($day) || !isset($month) || !isset($year)){
                throw new Exception("Invalid/Date PArameters");
            }
            if(!checkdate($month, $day, $year)){
                throw new Exception("Invalid/Missing Date of Birth");
            }

            $date_of_birth = strtotime( $date_of_birth );

            return $date_of_birth;
        }catch( Exception $e ){
            return $e->getMessage();
        }
    }

}
echo zebra::set_date_of_birth('19-11-2015');
echo '<br />';
echo zebra::set_date_of_birth('19-11-15');
/* 
    and the output was:-
    1447891200
    Invalid Date Format 
*/