當前位置: 首頁>>代碼示例>>PHP>>正文


PHP DataValidator::addRule方法代碼示例

本文整理匯總了PHP中DataValidator::addRule方法的典型用法代碼示例。如果您正苦於以下問題:PHP DataValidator::addRule方法的具體用法?PHP DataValidator::addRule怎麽用?PHP DataValidator::addRule使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在DataValidator的用法示例。


在下文中一共展示了DataValidator::addRule方法的2個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的PHP代碼示例。

示例1: validate

 /**
  * Check if data are valide
  *
  * @return boolean
  */
 public function validate()
 {
     // use validator library
     require_once dirname(__FILE__) . '/../datavalidator.lib.php';
     // new validator
     $validator = new DataValidator();
     $dataList = array('name' => $this->name, 'description' => $this->description);
     $validator->setDataList($dataList);
     $validator->addRule('name', get_lang('Name is missing'), 'required');
     // $validator->addRule('description',get_lang('Description is missing'),'required');
     if ($validator->validate(DATAVALIDATOR_STRICT_MODE)) {
         return true;
     } else {
         $this->errorList = $validator->getErrorList();
         return false;
     }
 }
開發者ID:rhertzog,項目名稱:lcs,代碼行數:22,代碼來源:profile.class.php

示例2: user_validate_form

/**
 * Validate user form.
 *
 * @author Hugues Peeters <hugues.peeters@claroline.net>
 * @author Frederic Minne <zefredz@claroline.net>
 * @param string $mode 'registration' or 'profile' or 'admin_user_profile'
 * @param array $data to fill the form
 * @param int $userId (optional) id of the user account currently edited
 * @return array with error messages
 */
function user_validate_form($formMode, $data, $userId = null)
{
    require_once dirname(__FILE__) . '/datavalidator.lib.php';
    if (empty($userId) || claro_is_platform_admin()) {
        $editableFields = array('name', 'official_code', 'login', 'password', 'email', 'phone', 'language', 'picture', 'skype');
        if (claro_is_platform_admin()) {
            $editableFields[] = 'authSource';
        }
    } else {
        // $editableFields = get_conf('profile_editable');
        $editableFields = AuthProfileManager::getUserAuthProfile($userId)->getEditableProfileFields();
    }
    $validator = new DataValidator();
    $validator->setDataList($data);
    if (in_array('name', $editableFields)) {
        $validator->addRule('lastname', get_lang('You left some required fields empty'), 'required');
        $validator->addRule('firstname', get_lang('You left some required fields empty'), 'required');
    }
    if (in_array('login', $editableFields)) {
        $validator->addRule('username', get_lang('You left some required fields empty'), 'required');
        $validator->addRule('username', get_lang('Username is too long (maximum 60 characters)'), 'maxlength', 60);
    }
    if (in_array('email', $editableFields) && !get_conf('userMailCanBeEmpty')) {
        $validator->addRule('email', get_lang('You left some required fields empty'), 'required');
    }
    if (in_array('official_code', $editableFields) && !get_conf('userOfficialCodeCanBeEmpty')) {
        $validator->addRule('officialCode', get_lang('You left some required fields empty'), 'required');
    }
    if (in_array('password', $editableFields) && (array_key_exists('password', $data) || array_key_exists('password_conf', $data))) {
        if ($formMode != 'registration' && $formMode != 'admin_user_profile') {
            $userProperties = user_get_properties($userId);
            $validator->addRule('old_password', get_lang('You left some required fields empty'), 'required');
            $validator->addRule('old_password', get_lang('Old password is wrong'), 'user_check_authentication', array($userProperties['username']));
        }
        if (get_conf('SECURE_PASSWORD_REQUIRED')) {
            $validator->addRule('password', get_lang('This password is too simple or too close to the username, first name or last name.<br> Use a password like this <code>%passProposed</code>', array('%passProposed' => generate_passwd())), 'is_password_secure_enough', array(array($data['username'], $data['officialCode'], $data['lastname'], $data['firstname'], $data['email'])));
        }
        $validator->addRule('password', get_lang('You typed two different passwords'), 'compare', $data['password_conf']);
    }
    $validator->addRule('email', get_lang('The email address is not valid'), 'email');
    if ('registration' == $formMode) {
        $validator->addRule('password_conf', get_lang('You left some required fields empty'), 'required');
        $validator->addRule('officialCode', get_lang('This official code is already used by another user.'), 'is_official_code_available');
        $validator->addRule('username', get_lang('This username is already taken'), 'is_username_available');
        $validator->addRule('password', get_lang('You left some required fields empty'), 'required');
    } else {
        // FIX for the empty password issue
        if (!empty($data['password']) || !empty($data['password_conf'])) {
            $validator->addRule('password', get_lang('You left some required fields empty'), 'required');
        }
        $validator->addRule('officialCode', get_lang('This official code is already used by another user.'), 'is_official_code_available', $userId);
        $validator->addRule('username', get_lang('This username is already taken'), 'is_username_available', $userId);
    }
    if ($validator->validate()) {
        return array();
    } else {
        return array_unique($validator->getErrorList());
    }
}
開發者ID:rhertzog,項目名稱:lcs,代碼行數:69,代碼來源:user.lib.php


注:本文中的DataValidator::addRule方法示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。