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


PHP Gdn_Validation::AddRule方法代码示例

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


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

示例1: ProfileController_MyProfileEdit_Create

 public function ProfileController_MyProfileEdit_Create($Sender, $Args)
 {
     $sfYaml = Gdn::Factory('sfYaml');
     $Sender->UserID = ArrayValue(0, $Args, '');
     $Sender->UserName = ArrayValue(1, $Args, '');
     $Sender->GetUserInfo($Sender->UserID, $Sender->UserName);
     $SessionUserID = Gdn::Session()->UserID;
     if ($Sender->User->UserID != $SessionUserID) {
         $Sender->Permission('Garden.Users.Edit');
         $MyMetaUserID = $Sender->User->UserID;
     } else {
         $MyMetaUserID = $SessionUserID = Gdn::Session()->UserID;
     }
     if (file_exists(dirname(__FILE__) . DS . 'mymeta.yml')) {
         $Meta = $sfYaml->load(dirname(__FILE__) . DS . 'mymeta.yml');
         $Sender->SetData('Example', false);
     } else {
         if (file_exists(dirname(__FILE__) . DS . 'mymeta.yml.example')) {
             $Meta = $sfYaml->load(dirname(__FILE__) . DS . 'mymeta.yml.example');
             $Sender->SetData('Example', true);
         }
     }
     $Sender->Form = new Gdn_Form();
     $ValidationFailed = false;
     if ($Sender->Form->AuthenticatedPostBack() === FALSE) {
         $Sender->Form->SetData($Sender->MyProfile);
     } else {
         $Data = $Sender->Form->FormValues();
         $Validation = new Gdn_Validation();
         foreach ($Data as $DataI => $DataV) {
             $Field = $Meta['MyMeta'][$DataI];
             if (GetValue('required', $Field)) {
                 $Validation->ApplyRule($DataI, 'Required', sprintf(T('%s is required'), $Field['name']));
             }
             foreach (GetValue('requiredwith', $Field) as $RequiredWith) {
                 if (!GetValue($RequiredWith, $Datarequired)) {
                     $Validation->ApplyRule($RequiredWith, 'Required', sprintf(T('%s is required with %s'), $Meta['MyMeta'][$RequiredWith]['name'], $Field['name']));
                 }
             }
             if (empty($DataV)) {
                 continue;
             }
             if ($V = GetValue('validate', $Field)) {
                 if (strpos($V, 'Validate') === 0) {
                     //Begins with
                     $V = substr($V, 8);
                     if (function_exists($V)) {
                         $Validation->AddRule($V, 'function:' . $V);
                     } else {
                         if (function_exists($V)) {
                             $Validation->AddRule($V, 'function:Validate' . $V);
                         }
                     }
                 }
                 $Validation->ApplyRule($DataI, $V, sprintf(T('%s not valid'), $Field['name']));
             }
             if ($R = GetValue('validateregex', $Field)) {
                 $Validation->AddRule($DataI, 'regex:`^' . $R . '$`i');
                 $Validation->ApplyRule($DataI, $DataI, sprintf(T('%s not valid'), $Field['name']));
             }
             if ($M = GetValue('maxchar', $Field)) {
                 $Validation->AddRule('MaxLen' . $DataI, 'regex:`^.{0,' . $M . '}$`is');
                 $Validation->ApplyRule($DataI, 'MaxLen' . $DataI, sprintf(T('%s not cannot be longer than %s chars'), $Field['name'], $M));
             }
         }
         $Validation->Validate($Data);
         if (count($Validation->Results()) == 0) {
             $MyMeta = array_intersect_key($Data, $Meta['MyMeta']);
             UserModel::SetMeta($MyMetaUserID, $MyMeta, 'MyMeta.');
         } else {
             $ValidationFailed = true;
         }
         $Sender->Form->SetValidationResults($Validation->Results());
     }
     if (!$ValidationFailed) {
         $Data = UserModel::GetMeta($MyMetaUserID, 'MyMeta.%', 'MyMeta.');
     }
     $MyMeta = array_intersect_key($Data, $Meta['MyMeta']);
     $Sender->SetData('Fields', $Meta['MyMeta']);
     $Sender->SetData('MyMeta', $MyMeta);
     $Sender->View = dirname(__FILE__) . DS . 'views' . DS . 'edit.php';
     $Sender->Render();
 }
开发者ID:seedbank,项目名称:old-repo,代码行数:83,代码来源:default.php


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