本文整理汇总了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;
}
}
示例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);
}
示例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) {