打印过滤器规则在gump库中不起作用

时间:2018-12-22 04:29:50

标签: php validation

我有以下代码用于检查邮寄数据:

public function register_action()
{
    $this->Language->load('account/register');
    try {
        // Run CSRF check, on POST data, in exception mode, with a validity of 10 minutes, in one-time mode.
       // Csrf::check('csrf_token', $_POST, true, 60 * 10, false);

        $gump = new \App\Core\Validate\GUMP('en');

        $_POST = $gump->sanitize($_POST); // You don't have to sanitize, but it's safest to do so.

        $gump->set_field_name('customer_username', $this->Language->get('text_username'));

        $gump->validation_rules(array(
            'customer_username' => 'required|alpha_numeric|max_len,12|min_len,6',
        ));

        $gump->filter_rules(array(
            'customer_username' => 'trim|sanitize_string|lower_case',
        ));

        $validated_data = $gump->run($_POST);

        if ($validated_data === false) {
            $errors = [$gump->get_readable_errors(true)];
            $this->templates->addData(['errors' => $errors], 'account/register');
            return $this->index();
        } else {

            try {

                echo $_POST['customer_username'];

            } catch (\Exception $e) {
                $errors = [$this->Language->get($e->getMessage())];
                $this->templates->addData(['errors' => $errors], 'account/register');
                return $this->index();
            }

        }

    } catch (\Exception $e) {
        Response::redirectBack('account/register');
        exit();
    }
}

在实践中,验证规则可以正常工作,但是当我需要打印过滤器规则时,我的代码不起作用,即:

我将以下数据发送给customer_username:AAAAAAAAAA

我将“过滤器”规则设置为:小写并使用回显$_POST['customer_username'];

打印

但是在输出中,我看到:AAAAAAAAAA

如何解决此错误并打印过滤的数据?

0 个答案:

没有答案