当前位置: 首页>>代码示例>>PHP>>正文


PHP GUMP::add_validator方法代码示例

本文整理汇总了PHP中GUMP::add_validator方法的典型用法代码示例。如果您正苦于以下问题:PHP GUMP::add_validator方法的具体用法?PHP GUMP::add_validator怎么用?PHP GUMP::add_validator使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在GUMP的用法示例。


在下文中一共展示了GUMP::add_validator方法的3个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。

示例1: save

 public function save()
 {
     GUMP::add_validator("unique", function ($field, $input, $param = NULL) {
         $checkExistingUser = R::findOne('user', 'user=?', array($input));
         if ($checkExistingUser == NULL) {
             return FALSE;
         } else {
             return TRUE;
         }
     });
     GUMP::add_validator("strong", function ($field, $input, $param = NULL) {
         return checkPasswordStrength($input);
     });
     $rules = array('reseller_username' => 'required|alpha_numeric|max_len,10|min_len,6|unique', 'reseller_password' => 'required|max_len,10|min_len,7|strong');
     $filters = array('reseller_username' => 'trim|sanitize_string', 'reseller_password' => 'trim|sanitize_string|md5');
     $app = Slim::getInstance();
     $post = $app->request()->post();
     // $app - Slim main app instance
     $postValues = $gump->filter($post, $filters);
     $validated = $gump->validate($gump->filter($postValues, $filters), $rules);
     if ($validated === TRUE) {
         $createUser = R::dispense('user');
         $createUser->user = $postValues['reseller_username'];
         $createUser->user = $postValues['reseller_password'];
     } else {
         $this->setError($gump->get_readable_errors(true));
     }
     if ($this->getError() == "") {
         $this->fails = FALSE;
     } else {
         $this->fails = TRUE;
     }
 }
开发者ID:bogiesoft,项目名称:Slim_PHP_Project,代码行数:33,代码来源:reseller_library.php

示例2: function

#!/usr/bin/php -q
<?php 
require "../gump.class.php";
// Add the custom validator
GUMP::add_validator("is_object", function ($field, $input, $param = NULL) {
    return is_object($input[$field]);
});
// Generic test data
$input_data = array('not_object' => 5, 'valid_object' => new stdClass());
$rules = array('not_object' => "required|is_object", 'valid_object' => "required|is_object");
// METHOD 1 (Long):
$validator = new GUMP();
$validated = $validator->validate($input_data, $rules);
if ($validated === true) {
    echo "Validation passed!";
} else {
    echo $validator->get_readable_errors(true);
}
// METHOD 2 (Short):
$is_valid = GUMP::is_valid($input_data, $rules);
if ($is_valid === true) {
    echo "Validation passed!";
} else {
    print_r($is_valid);
}
开发者ID:JON4TH4NHUNT3R,项目名称:cars-4-hire,代码行数:25,代码来源:custom_validator.php

示例3: function

});
$app->map('/signup', function () use($app) {
    if ($app->request->post()) {
        $post['username'] = $app->request->post('username');
        $post['email'] = $app->request->post('email');
        # https://github.com/Wixel/GUMP
        $gump = new GUMP();
        GUMP::add_validator('istaken', function ($field, $input, $param = NULL) {
            if (!empty($input[$field])) {
                $app = \Slim\Slim::getInstance();
                # http://stackoverflow.com/questions/4364686/how-do-i-sanitize-input-with-pdo
                # https://youtu.be/sRfYgco3xo4?t=1758
                $sql = 'SELECT name FROM users WHERE name=:name OR email=:name';
                $user = $app->db->prepare($sql);
                /*** bind the paramaters ***/
                $user->bindParam(':name', $input[$field], PDO::PARAM_STR);
                /*** execute the prepared statement ***/
                $user->execute();
                $user = $user->fetch(PDO::FETCH_ASSOC);
                if (is_array($user)) {
                    return false;
                }
            }
        });
        $validation_rules_1 = array('username' => 'required|min_len,6|alpha_space|istaken', 'email' => 'required|valid_email|istaken', 'password' => 'required', 'password_confirm' => 'required');
        $validation_rules_2 = array('username' => 'required|min_len,6|alpha_space', 'email' => 'required|valid_email', 'password' => 'required', 'password_confirm' => 'required');
        $gump->validation_rules($validation_rules_1);
        $filter_array = array('username' => 'trim|sanitize_string|rmpunctuation', 'email' => 'trim|sanitize_string|sanitize_email', 'password' => 'trim', 'password_confirm' => 'trim');
        $gump->filter_rules($filter_array);
        $validated_data = $gump->run($app->request->post());
        if ($validated_data !== false) {
开发者ID:WebstudioNoord,项目名称:notes,代码行数:31,代码来源:user.router.php


注:本文中的GUMP::add_validator方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。