PHP - GUMP验证类

时间:2016-03-05 07:38:27

标签: php validation

我需要使用GUMP验证类来验证我的表单数据,但是如何单独获取每个字段错误

如何显示每个字段错误

<?php

    if (isset($_POST['submit'])){
        require "gump.class.php";
        $validator = new GUMP();
        $us = $_POST['username'];
        $pwd = $_POST['password'];
        // Set the data
        $_POST = array('username' => $us,'password' => $pwd);
        $_POST = $validator->sanitize($_POST);
        $rules = array('username' => 'required','password' => 'required|max_len,100|min_len,6');
        $filters = array('username' => 'trim|sanitize_string','password' => 'trim|base64_encode');
        $_POST = $validator->filter($_POST, $filters);
        $validated = $validator->validate($_POST, $rules);

        if ($validated === TRUE){
            echo "Successful Validation\n\n";
            print_r($_POST);
            exit;
        } else {
            echo $validator->get_readable_errors(true);
        }

    }

    ?>

1 个答案:

答案 0 :(得分:0)

github code的攻击,有 get_errors_array 方法,该方法应返回包含字段名称作为键的错误数组