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


PHP Validator::required方法代码示例

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


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

示例1: validate

 function validate()
 {
     $validator = new Validator($this->_value);
     if ($this->isRequired()) {
         $validator->required(sprintf("%s cannot be blank", $this->getName()));
     }
     $this->_errors = $validator->allErrors();
     return $this->allErrors();
 }
开发者ID:etenil,项目名称:assegai,代码行数:9,代码来源:Field.php

示例2: text

 /**
  * @return boolean Returns true when successful.
  */
 private static function text($connection, $type, $function, $line, $text = '')
 {
     // Check dependencies
     Validator::required(isset($connection, $type, $function, $line, $text), __METHOD__);
     // Get time
     $sysstamp = time();
     // Save in database
     $query = Database::prepare($connection, "INSERT INTO ? (time, type, function, line, text) VALUES ('?', '?', '?', '?', '?')", array(LYCHEE_TABLE_LOG, $sysstamp, $type, $function, $line, $text));
     $result = Database::execute($connection, $query, null, null);
     if ($result === false) {
         return false;
     }
     return true;
 }
开发者ID:windhamdavid,项目名称:Lychee,代码行数:17,代码来源:Log.php

示例3: ValidateInput

function ValidateInput()
{
    if ($_SERVER['CONTENT_LENGTH'] > getPhpConfBytes()) {
        FormPage::GetInstance()->SetErrors(array(array('field' => 'Form', 'err' => _T('The form is attempting to send more data than the server allows. Please check that you are not uploading too many large files.'))));
        return 1;
    }
    $cfg = Config::GetInstance()->GetConfig('rules');
    if ($cfg === false) {
        return 1;
    }
    $validator = new Validator();
    $conditionals = new Conditionals();
    foreach ($cfg as $name => $rules) {
        // skip all rules that have a name with a _ prefix
        if ($name[0] == '_') {
            continue;
        }
        if ($conditionals->IsFieldIgnored($name)) {
            continue;
        }
        $fieldtype = $rules->fieldtype;
        if (method_exists('Validator', $fieldtype)) {
            if (!$validator->required($name, $rules)) {
                continue;
            } else {
                $validator->{$fieldtype}($name, $rules);
            }
        } else {
            writeErrorLog('Validation handler missing for fieldtype: ', $fieldtype);
        }
    }
    $errcount = count($validator->errors);
    // ready, assign the result to the page instance
    if ($errcount > 0) {
        FormPage::GetInstance()->SetErrors($validator->errors);
    } else {
        FormPage::GetInstance()->SetPostValues($validator->post);
    }
    return $errcount;
}
开发者ID:Methunter,项目名称:agency,代码行数:40,代码来源:validator.inc.php

示例4: subscribeNewsletter

 public function subscribeNewsletter()
 {
     $validator = new Validator();
     $req = array('subscriber_email' => t("Email is required"));
     $req_email = array('subscriber_email' => t("Email address seems invalid"));
     $validator->required($req, $this->data);
     $validator->email($req_email, $this->data);
     if (Yii::app()->functions->getSubsriberEmail($this->data['subscriber_email'])) {
         $validator->msg[] = t("Sorry your Email address is already exist in our records.");
     }
     if ($validator->validate()) {
         $params = array('email_address' => $this->data['subscriber_email'], 'date_created' => date('c'), 'ip_address' => $_SERVER['REMOTE_ADDR']);
         if ($this->insertData("{{newsletter}}", $params)) {
             $this->code = 1;
             $this->msg = t("Thank you for subscribing to our mailing list!");
         } else {
             $this->msg = t("Sorry there is error while we saving your information.");
         }
     } else {
         $this->msg = $validator->getErrorAsHTML();
     }
 }
开发者ID:ashishvazirani,项目名称:food,代码行数:22,代码来源:AjaxAdmin.php

示例5: setPassword

 /**
  * Sets a new username.
  * @return boolean Returns true when successful.
  */
 private static function setPassword($password)
 {
     // Check dependencies
     Validator::required(isset($password), __METHOD__);
     // Hash password
     $password = getHashedString($password);
     // Do not prepare $password because it is hashed and save
     // Preparing (escaping) the password would destroy the hash
     if (self::set('password', $password, true) === false) {
         return false;
     }
     return true;
 }
开发者ID:windhamdavid,项目名称:Lychee,代码行数:17,代码来源:Settings.php

示例6: hash

         $retHashSeq = $merchant_salt . '|' . $status . '|||||||||||' . $email . '|' . $firstname . '|' . $productinfo . '|' . $amount . '|' . $txnid . '|' . $key;
     }
     $hash = hash("sha512", $retHashSeq);
     if ($hash == $posted_hash) {
         if ($status == "success") {
             $success = true;
         } else {
             $error1 = Yii::t("default", "Transaction failed." . " " . $status);
         }
     } else {
         $error1 = Yii::t("default", "Invalid Transaction. Please try again");
     }
 } else {
     $Validator = new Validator();
     $req = array('firstname' => Yii::t("default", "First name is required"), 'email' => Yii::t("default", "Email address is required"), 'phone' => Yii::t("default", "Phone is required"));
     $Validator->required($req, $data_post);
     if ($Validator->validate()) {
         //$amount_to_pay=number_format($amount_to_pay,0);
         $amount_to_pay = normalPrettyPrice($amount_to_pay);
         $hash_string = "{$merchant_key}|{$payment_ref}|{$amount_to_pay}|{$payment_description}|";
         $hash_string .= $data_post['firstname'] . "|";
         $hash_string .= $data_post['email'] . "|||||||||||";
         $hash_string .= $merchant_salt;
         $merchant_hash = strtolower(hash('sha512', $hash_string));
         $action = $PAYU_BASE_URL . '/_payment';
         /*dump($hash_string);
           dump($action);
           die();*/
     } else {
         $error1 = $Validator->getErrorAsHTML();
     }
开发者ID:ashishvazirani,项目名称:food,代码行数:31,代码来源:payu.php

示例7: validateColumns

 public function validateColumns($datarow)
 {
     if (!is_a($datarow, 'ModelDataRow')) {
         throw new InvalidModelException('Argument type mismatch (ModelDataRow expected, ' . gettype($datarow) . ' found)');
     }
     $error = array();
     foreach ($this->getSchema()['columns'] as $column => $columnSchema) {
         $value = $datarow->{$column};
         $isRequired = FALSE;
         /*
          * Check if the field is required, i.e. must be filled
          */
         if (isset($columnSchema['rule'])) {
             if (in_array('required', $columnSchema['rule'])) {
                 $isRequired = TRUE;
                 if (!Validator::required($value)) {
                     $this->lastError[$column][] = 'required';
                     continue;
                 }
             }
         }
         if (!$isRequired) {
             /*
              * If the column is not a required field, only performs 
              * checking when the field is non-empty
              */
             if (!Validator::nonEmpty($value)) {
                 continue;
             }
         }
         /*
          * Perform type checking
          */
         if ($columnSchema['type'] == 'array') {
             if (!Validator::arraytype($value)) {
                 $error[$column][] = 'array';
             }
             $datarow->{$column} = json_encode($datarow->{$column});
         } elseif ($columnSchema['type'] == 'object') {
             if (!Validator::object($value)) {
                 $error[$column][] = 'object';
             }
             $datarow->{$column} = json_encode($datarow->{$column});
         } elseif ($columnSchema['type'] == 'universial') {
             // no type checking needed
         } else {
             if (!call_user_func(array('Validator', $columnSchema['type']), $value)) {
                 $error[$column][] = $columnSchema['type'];
             }
         }
         /*
          * Perform rule checking
          */
         if (isset($columnSchema['rule'])) {
             foreach ($columnSchema['rule'] as $rule) {
                 if (is_array($rule)) {
                     if (method_exists('Validator', $rule[0])) {
                         $parameters = array_slice($rule, 1);
                         array_unshift($parameters, $value);
                         if (!call_user_func_array(array('Validator', $rule[0]), $parameters)) {
                             $error[$column][] = $rule[0];
                         }
                     }
                 } else {
                     /*
                      * Special case, the rule is unique
                      */
                     if ($rule == 'unique') {
                         if ($datarow->id == NULL) {
                             if (!$this->unique($column, $value)) {
                                 $error[$column][] = 'unique';
                             }
                         } else {
                             if (!$this->unique($column, $value, $datarow->id)) {
                                 $error[$column][] = 'unique';
                             }
                         }
                     } else {
                         if (method_exists('Validator', $rule)) {
                             if (!call_user_func(array('Validator', $rule), $value)) {
                                 $error[$column][] = $rule;
                             }
                         }
                     }
                 }
             }
         }
     }
     if (count($error) > 0) {
         $this->lastError = $error;
         return FALSE;
     }
     return TRUE;
 }
开发者ID:yuhlau,项目名称:simphpfy,代码行数:94,代码来源:Model.php

示例8: addDish

 public function addDish()
 {
     $Validator = new Validator();
     $req = array('dish_name' => Yii::t("default", "Dish name is required"), 'spicydish' => t("Icon is required"));
     $Validator->required($req, $this->data);
     if ($Validator->validate()) {
         $params = array('dish_name' => $this->data['dish_name'], 'photo' => $this->data['spicydish'], 'status' => $this->data['status'], 'date_created' => date('c'), 'ip_address' => $_SERVER['REMOTE_ADDR']);
         if (empty($this->data['id'])) {
             if ($this->insertData("{{dishes}}", $params)) {
                 $this->details = Yii::app()->db->getLastInsertID();
                 $this->code = 1;
                 $this->msg = Yii::t("default", "Successful");
             }
         } else {
             unset($params['date_created']);
             $params['date_modified'] = date('c');
             $res = $this->updateData('{{dishes}}', $params, 'dish_id', $this->data['id']);
             if ($res) {
                 $this->code = 1;
                 $this->msg = Yii::t("default", 'Dish updated');
             } else {
                 $this->msg = Yii::t("default", "ERROR: cannot update");
             }
         }
     } else {
         $this->msg = $Validator->getErrorAsHTML();
     }
 }
开发者ID:ashishvazirani,项目名称:food,代码行数:28,代码来源:Ajax.php


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