当前位置: 首页>>代码示例>>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;未经允许,请勿转载。