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


PHP GFFormDisplay::is_empty方法代码示例

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


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

示例1: custom_validation

 /**
  * Make validation work for Edit Entry
  *
  * Because we're calling the GFFormDisplay::validate() in an unusual way (as a front-end
  * form pretending to be a back-end form), validate() doesn't know we _can't_ edit post
  * fields. This goes through all the fields and if they're an invalid post field, we
  * set them as valid. If there are still issues, we'll return false.
  *
  * @param  [type] $validation_results [description]
  * @return [type]                     [description]
  */
 function custom_validation($validation_results)
 {
     do_action('gravityview_log_debug', 'GravityView_Edit_Entry[custom_validation] Validation results: ', $validation_results);
     do_action('gravityview_log_debug', 'GravityView_Edit_Entry[custom_validation] $_POSTed data (sanitized): ', esc_html(print_r($_POST, true)));
     $gv_valid = true;
     foreach ($validation_results['form']['fields'] as $key => &$field) {
         $value = RGFormsModel::get_field_value($field);
         $field_type = RGFormsModel::get_input_type($field);
         // Validate always
         switch ($field_type) {
             case 'fileupload':
                 // in case nothing is uploaded but there are already files saved
                 if (!empty($field->failed_validation) && !empty($field->isRequired) && !empty($value)) {
                     $field->failed_validation = false;
                     unset($field->validation_message);
                 }
                 // validate if multi file upload reached max number of files [maxFiles] => 2
                 if (rgar($field, 'maxFiles') && rgar($field, 'multipleFiles')) {
                     $input_name = 'input_' . $field->id;
                     //uploaded
                     $file_names = isset(GFFormsModel::$uploaded_files[$validation_results['form']['id']][$input_name]) ? GFFormsModel::$uploaded_files[$validation_results['form']['id']][$input_name] : array();
                     //existent
                     $entry = $this->get_entry();
                     $value = NULL;
                     if (isset($entry[$field->id])) {
                         $value = json_decode($entry[$field->id], true);
                     }
                     // count uploaded files and existent entry files
                     $count_files = count($file_names) + count($value);
                     if ($count_files > $field->maxFiles) {
                         $field->validation_message = __('Maximum number of files reached', 'gravityview');
                         $field->failed_validation = 1;
                         $gv_valid = false;
                         // in case of error make sure the newest upload files are removed from the upload input
                         GFFormsModel::$uploaded_files[$validation_results['form']['id']] = null;
                     }
                 }
                 break;
         }
         // This field has failed validation.
         if (!empty($field->failed_validation)) {
             do_action('gravityview_log_debug', 'GravityView_Edit_Entry[custom_validation] Field is invalid.', array('field' => $field, 'value' => $value));
             switch ($field_type) {
                 // Captchas don't need to be re-entered.
                 case 'captcha':
                     // Post Image fields aren't editable, so we un-fail them.
                 // Post Image fields aren't editable, so we un-fail them.
                 case 'post_image':
                     $field->failed_validation = false;
                     unset($field->validation_message);
                     break;
             }
             // You can't continue inside a switch, so we do it after.
             if (empty($field->failed_validation)) {
                 continue;
             }
             // checks if the No Duplicates option is not validating entry against itself, since
             // we're editing a stored entry, it would also assume it's a duplicate.
             if (!empty($field->noDuplicates)) {
                 $entry = $this->get_entry();
                 // If the value of the entry is the same as the stored value
                 // Then we can assume it's not a duplicate, it's the same.
                 if (!empty($entry) && $value == $entry[$field->id]) {
                     //if value submitted was not changed, then don't validate
                     $field->failed_validation = false;
                     unset($field->validation_message);
                     do_action('gravityview_log_debug', 'GravityView_Edit_Entry[custom_validation] Field not a duplicate; it is the same entry.', $entry);
                     continue;
                 }
             }
             // if here then probably we are facing the validation 'At least one field must be filled out'
             if (GFFormDisplay::is_empty($field, $this->form_id) && empty($field->isRequired)) {
                 unset($field->validation_message);
                 $field->validation_message = false;
                 continue;
             }
             $gv_valid = false;
         }
     }
     $validation_results['is_valid'] = $gv_valid;
     do_action('gravityview_log_debug', 'GravityView_Edit_Entry[custom_validation] Validation results.', $validation_results);
     // We'll need this result when rendering the form ( on GFFormDisplay::get_form )
     $this->form_after_validation = $validation_results['form'];
     return $validation_results;
 }
开发者ID:hansstam,项目名称:makerfaire,代码行数:96,代码来源:class-edit-entry-render.php

示例2: validate

 private function validate(&$form, $field_values)
 {
     $form = apply_filters('gform_pre_validation', $form);
     foreach ($form["fields"] as &$field) {
         /*
          * Skip over the following fields as we aren't processing any of them
          */
         $skip_field = false;
         switch (RGFormsModel::get_input_type($field)) {
             case "captcha":
             case "html":
             case "password":
             case "product":
             case "coupon":
             case "quantity":
             case "shipping":
             case "donation":
             case "total":
             case "singleproduct":
             case "hiddenproduct":
             case "singleshipping":
             case "creditcard":
             case "page":
             case "post_image":
             case "fileupload":
                 //ignore certain fields
                 $skip_field = true;
                 break;
         }
         if (isset($field['productField']) && (int) $field['productField'] > 0 || $field['type'] == 'shipping') {
             $skip_field = true;
         }
         /* ignore validation if field is hidden or admin only */
         if (RGFormsModel::is_field_hidden($form, $field, $field_values) || isset($field['adminOnly']) && $field['adminOnly']) {
             $skip_field = true;
         }
         /* ignore user-defined restricted fields or hidden fields */
         if (in_array($field['id'], $this->atts['restricted_fields']) || in_array($field['id'], $this->atts['hidden_fields'])) {
             $skip_field = true;
         }
         if ($skip_field) {
             continue;
         }
         $value = RGFormsModel::get_field_value($field);
         //display error message if field is marked as required and the submitted value is empty
         if ($field["isRequired"] && GFFormDisplay::is_empty($field, $form["id"])) {
             $field["failed_validation"] = true;
             $field["validation_message"] = empty($field["errorMessage"]) ? __("This field is required.", "gravityforms") : $field["errorMessage"];
         } else {
             if ($field["noDuplicates"] && RGFormsModel::is_duplicate($form["id"], $field, $value)) {
                 $field["failed_validation"] = true;
                 $input_type = RGFormsModel::get_input_type($field);
                 switch ($input_type) {
                     case "date":
                         $default_message = __("This date has already been taken. Please select a new date.", "gravityforms");
                         break;
                     default:
                         $default_message = is_array($value) ? __("This field requires a unique entry and the values you entered have been already been used.", "gravityforms") : sprintf(__("This field requires a unique entry and '%s' has already been used", "gravityforms"), $value);
                         break;
                 }
                 $field["validation_message"] = apply_filters("gform_duplicate_message_{$form["id"]}", apply_filters("gform_duplicate_message", $default_message, $form, $field, $value), $form, $field, $value);
             } else {
                 if (GFFormDisplay::failed_state_validation($form["id"], $field, $value)) {
                     $field["failed_validation"] = true;
                     $field["validation_message"] = in_array($field["inputType"], array("singleproduct", "singleshipping", "hiddenproduct")) ? __("Please enter a valid value.", "gravityforms") : __("Invalid selection. Please select one of the available choices.", "gravityforms");
                 } else {
                     switch (RGFormsModel::get_input_type($field)) {
                         case "name":
                             if ($field["isRequired"] && $field["nameFormat"] != "simple") {
                                 $first = $_POST["input_" . $field["id"] . "_3"];
                                 $last = $_POST["input_" . $field["id"] . "_6"];
                                 if (empty($first) || empty($last)) {
                                     $field["failed_validation"] = true;
                                     $field["validation_message"] = empty($field["errorMessage"]) ? __("This field is required. Please enter the first and last name.", "gravityforms") : $field["errorMessage"];
                                 }
                             }
                             break;
                         case "address":
                             if ($field["isRequired"]) {
                                 $street = $_POST["input_" . $field["id"] . "_1"];
                                 $city = $_POST["input_" . $field["id"] . "_3"];
                                 $state = $_POST["input_" . $field["id"] . "_4"];
                                 $zip = $_POST["input_" . $field["id"] . "_5"];
                                 $country = $_POST["input_" . $field["id"] . "_6"];
                                 if (empty($street) || empty($city) || empty($zip) || empty($state) && !$field["hideState"] || empty($country) && !$field["hideCountry"]) {
                                     $field["failed_validation"] = true;
                                     $field["validation_message"] = empty($field["errorMessage"]) ? __("This field is required. Please enter a complete address.", "gravityforms") : $field["errorMessage"];
                                 }
                             }
                             break;
                         case "email":
                             if (!rgblank($value) && !GFCommon::is_valid_email($value)) {
                                 $field["failed_validation"] = true;
                                 $field["validation_message"] = empty($field["errorMessage"]) ? __("Please enter a valid email address.", "gravityforms") : $field["errorMessage"];
                             } else {
                                 if (rgget("emailConfirmEnabled", $field) && !empty($value)) {
                                     $confirm = rgpost("input_" . $field["id"] . "_2");
                                     if ($confirm != $value) {
                                         $field["failed_validation"] = true;
                                         $field["validation_message"] = __("Your emails do not match.", "gravityforms");
//.........这里部分代码省略.........
开发者ID:Ezyva2015,项目名称:SMSF-Academy-Wordpress,代码行数:101,代码来源:entry-edit-logic.php


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