本文整理汇总了PHP中validation::addRule方法的典型用法代码示例。如果您正苦于以下问题:PHP validation::addRule方法的具体用法?PHP validation::addRule怎么用?PHP validation::addRule使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类validation
的用法示例。
在下文中一共展示了validation::addRule方法的8个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: forgotPwd
function forgotPwd()
{
global $req;
global $connection;
global $module;
$req->hasParams("email");
$email = $req->getParam("email");
$POST = array('email' => $email);
$val = new validation();
$val->addSource($POST);
$val->addRule('email', 'email', true, 2, 100, true);
$val->run();
if (sizeof($val->errors) > 0) {
$connection->close();
$errors = implode(" <br/> ", $val->errors);
Res::sendInvalid("Error: " . $errors);
} else {
$POST = $val->sanitized;
$email = $module->escape($POST['email']);
$output = $module->forgotPwd($email);
if (is_bool($output)) {
Res::sendInvalid($module->message);
} else {
$res = new Res();
$res->send();
}
}
}
示例2: addUsers
function addUsers()
{
global $req;
global $connection;
$req->hasParams("adminUName", "adminFName", "adminGender", "adminEMail", "adminPassword", "adminPhone");
$adminUName = $req->getParam("adminUName");
$adminFName = $req->getParam("adminFName");
$adminGender = $req->getParam("adminGender");
$adminEMail = $req->getParam("adminEMail");
$adminPassword = $req->getParam("adminPassword");
$adminPhone = $req->getParam("adminPhone");
$POST = array('adminUName' => $adminUName, 'adminFName' => $adminFName, 'adminGender' => $adminGender, 'adminEMail' => $adminEMail, 'adminPassword' => $adminPassword, 'adminPhone' => $adminPhone);
$genderValues = array('m', 'f', 'u');
$val = new validation();
$val->addSource($POST);
$val->addRule('adminUName', 'string', true, 2, 50, true)->addRule('adminFName', 'string', true, 2, 50, true)->addRule('adminGender', 'string', true, 1, 1, true)->addRule('adminEMail', 'email', true, 5, 100, true)->addRule('adminPassword', 'string', true, 4, 35, true)->addRule('adminPhone', 'string', true, 4, 20, true);
$val->run();
if (sizeof($val->errors) > 0) {
$errors = implode(" <br/> ", $val->errors);
Res::sendInvalid("Errors:" . $errors);
} else {
$POST = $val->sanitized;
$adminTable = new adminTable($connection);
$adminUName = $adminTable->escape($POST['adminUName']);
$adminFName = $adminTable->escape($POST['adminFName']);
$adminGender = $adminTable->escape($POST['adminGender']);
$adminEMail = $adminTable->escape($POST['adminEMail']);
$adminPassword = $adminTable->escape($POST['adminPassword']);
$adminPhone = $adminTable->escape($POST['adminPhone']);
$adminId = $adminTable->insertUsers($adminUName, $adminFName, $adminGender, $adminEMail, $adminPassword, $adminPhone);
if (is_bool($adminId)) {
Res::sendInvalid("Errors:" . $adminTable->message);
} else {
$res = new Res();
$res->addData("adminId", $adminId);
$res->send();
}
}
}
示例3: login
function login($user, $pwd, $rem)
{
global $adminSession;
global $adminCookieUser;
global $adminCookiePassword;
global $invalidUserIdOrPassword;
$POST = array('user' => $user, 'pwd' => $pwd, 'rem' => $rem);
$val = new validation();
$val->addSource($POST);
$val->addRule('user', 'string', true, 1, 35, true)->addRule('pwd', 'string', true, 1, 35, true)->addRule('rem', 'bool');
$val->run();
if (sizeof($val->errors) > 0) {
$connection->close();
$errors = implode(" <br/> ", $val->errors);
return "Error: " . $errors;
} else {
$POST = $val->sanitized;
$user = $this->escape($POST['user']);
$pwd = $this->escape($POST['pwd']);
$rem = $this->escape($POST['rem']);
$adminTable = new adminTable($this->connection);
$result = $adminTable->verifyAdminLogin($user, $pwd);
if (is_bool($result)) {
return $invalidUserIdOrPassword;
} else {
if (!isset($_SESSION)) {
session_start();
}
$_SESSION[$adminSession] = $result;
if ($rem) {
setcookie($adminCookieUser, $user, time() + 10 * 365 * 24 * 60 * 60, "/");
setcookie($adminCookiePassword, $pwd, time() + 10 * 365 * 24 * 60 * 60, "/");
}
return true;
}
}
}
示例4: foreach
$v1->addSource($_POST['course']);
$v1->addRule('name', 'string', true, 1, 200, true);
$v1->addRule('desc', 'string', true, 0, 999999, true);
if (isset($_POST['course']['pictureId']) && !empty($_POST['course']['pictureId'])) {
$v1->addRule('pictureId', 'numeric', true, 1, 999999, true);
}
foreach ($_POST['course'] as $key => $value) {
if (preg_match('/^[0-9]{1,}$/', $key)) {
$v1->addRule($key . "", 'numeric', true, 1, 200, true);
}
}
if (isset($_POST['course']['users'])) {
$v2->addSource($_POST['course']['users']);
foreach ($_POST['course']['users'] as $key => $value) {
if (preg_match('/^[0-9]{1,}$/', $key)) {
$v2->addRule($key . "", 'numeric', true, 1, 200, true);
}
}
}
$v1->run();
$v2->run();
if (sizeof($v1->errors) > 0 || sizeof($v2->errors)) {
$error_course_add = $v1->getMessageErrors() . "<br/>";
$error_course_add .= $v2->getMessageErrors();
} else {
$cats = array();
foreach ($v1->sanitized as $key => $value) {
if (preg_match('/^[0-9]{1,}$/', $key) && isIdCategoryWpExist($value)) {
$cats[] = $value;
}
}
示例5: StudyPressUserWP
$v->addRule('courseId', 'numeric', true, 1, 99999, true);
} else {
$v->errors['courseId'] = $tr->__("You must create a course");
}
$v->run();
if (sizeof($v->errors) > 0) {
$error_quiz_add = $v->getMessageErrors();
} else {
$currentUser = new StudyPressUserWP();
$id_quiz = $managerQuiz->add(new Quiz(array('pictureUrl' => isset($v->sanitized['pictureurl']) ? $v->sanitized['pictureurl'] : '', 'name' => $v->sanitized['name'], 'author' => $currentUser->displayName(), 'authorId' => $currentUser->id(), 'courseId' => $v->sanitized['courseId'])));
}
}
}
if (isset($_POST['remove'])) {
if (isset($_POST['id']) && !empty($_POST['id'])) {
$v = new validation();
$v->addSource($_POST['id']);
foreach ($_POST['id'] as $key => $value) {
$v->addRule($key, 'numeric', true, 1, 9999999, true);
}
$v->run();
if (sizeof($v->errors) > 0) {
$error_quiz_remove = $v->getMessageErrors();
} else {
foreach ($v->sanitized as $value) {
$managerQuiz->delete($value);
}
}
}
}
require_once __ROOT_PLUGIN__ . "Views/admin/quiz.view.php";
示例6: validation
<?php
require_once '_AutoLoadClassAjax.php';
if (isset($_POST['id']) && !empty($_POST['id'])) {
$v = new validation();
$v->addSource($_POST);
$v->addRule('id', 'numeric', true, 1, 99999, true);
$v->run();
if (sizeof($v->errors) === 0) {
$managerLesson = new LessonManager();
$managerQuiz = new QuizManager();
$activity = $managerLesson->getById($v->sanitized['id']);
if (!$activity) {
$activity = $managerQuiz->getById($v->sanitized['id']);
}
if ($activity) {
if (StudyPressUserWP::isLoggedIn()) {
$currentUserId = new StudyPressUserWP();
$currentUserId = $currentUserId->id();
$managerLesson->setVisitedActivity($currentUserId, $activity->getId());
}
}
}
}
示例7: validation
if (isset($v1->sanitized['pictureId'])) {
$course->setPictureId($v1->sanitized['pictureId']);
}
$managerCourse->update($course->getId(), $course);
}
}
} else {
$error_course_update = $tr->__("Please select at least one author") . "<br/>" . $tr->__("Please select at least one category") . "<br/>" . $tr->__("Please enter a valid name");
}
} else {
// if is an author
$v = new validation();
$v->addSource($_POST['course']);
$v->AddRules(array('id' => array('type' => 'numeric', "required" => true, 'min' => '1', 'max' => '999999', 'trim' => true), 'description' => array('type' => 'string', "required" => true, 'min' => '0', 'max' => '999999', 'trim' => true)));
if (isset($_POST['course']['pictureId']) && !empty($_POST['course']['pictureId'])) {
$v->addRule('pictureId', 'numeric', true, 1, 999999, true);
}
$v->run();
if (sizeof($v->errors)) {
$error_course_update = $v->getMessageErrors();
} else {
if ($course = $managerCourse->getById($v->sanitized['id'])) {
$course->setDescription($v->sanitized['description']);
if (isset($v->sanitized['pictureId'])) {
$course->setPictureId($v->sanitized['pictureId']);
}
$managerCourse->update($course->getId(), $course);
}
}
}
}
示例8: Configuration
}
}
}
}
}
}
if (isset($_POST['type']) && $_POST['type'] === "share-groups") {
if (isset($_POST['quizId']) && !empty($_POST['quizId']) && isset($_POST['groups'])) {
require_once "_AutoLoadClassAjax.php";
global $tr;
$c = new Configuration();
$c = $c->getConfig();
if ($c['bp_shareResult'] = 'true') {
$v = new validation();
$v->addSource($_POST);
$v->addRule('quizId', 'numeric', true, 1, 9999999, true);
$v->run();
if (sizeof($v->errors) > 0) {
header("HTTP/1.0 400 Bad Request");
echo $v->getMessageErrors();
} else {
$manager = new QuizManager();
$type = "quiz";
$activity = $manager->getById($v->sanitized['quizId']);
if (!$activity) {
$manager = new LessonManager();
$type = "lesson";
$activity = $manager->getById($v->sanitized['quizId']);
}
if ($activity) {
if (StudyPressUserWP::isLoggedIn()) {