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


PHP RGFormsModel::get_parameter_value方法代码示例

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


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

示例1: get_conditional_logic

 /**
  * Get init script and all necessary data for conditional logic.
  *
  * @todo: Replace much of the field value retrieval with a get_original_value() method in GF_Field class.
  *
  * @param       $form
  * @param array $field_values
  *
  * @return string
  */
 private static function get_conditional_logic($form, $field_values = array())
 {
     $logics = '';
     $dependents = '';
     $fields_with_logic = array();
     $default_values = array();
     foreach ($form['fields'] as $field) {
         /* @var GF_Field $field */
         $field_deps = self::get_conditional_logic_fields($form, $field->id);
         $field_dependents[$field->id] = !empty($field_deps) ? $field_deps : array();
         //use section's logic if one exists
         $section = RGFormsModel::get_section($form, $field->id);
         $section_logic = !empty($section) ? rgar($section, 'conditionalLogic') : null;
         $field_logic = $field->type != 'page' ? $field->conditionalLogic : null;
         //page break conditional logic will be handled during the next button click
         $next_button_logic = !empty($field->nextButton) && !empty($field->nextButton['conditionalLogic']) ? $field->nextButton['conditionalLogic'] : null;
         if (!empty($field_logic) || !empty($next_button_logic)) {
             $field_section_logic = array('field' => $field_logic, 'nextButton' => $next_button_logic, 'section' => $section_logic);
             $logics .= $field->id . ': ' . GFCommon::json_encode($field_section_logic) . ',';
             $fields_with_logic[] = $field->id;
             $peers = $field->type == 'section' ? GFCommon::get_section_fields($form, $field->id) : array($field);
             $peer_ids = array();
             foreach ($peers as $peer) {
                 $peer_ids[] = $peer->id;
             }
             $dependents .= $field->id . ': ' . GFCommon::json_encode($peer_ids) . ',';
         }
         //-- Saving default values so that they can be restored when toggling conditional logic ---
         $field_val = '';
         $input_type = $field->get_input_type();
         $inputs = $field->get_entry_inputs();
         //get parameter value if pre-populate is enabled
         if ($field->allowsPrepopulate) {
             if ($input_type == 'checkbox') {
                 $field_val = RGFormsModel::get_parameter_value($field->inputName, $field_values, $field);
                 if (!is_array($field_val)) {
                     $field_val = explode(',', $field_val);
                 }
             } elseif (is_array($inputs)) {
                 $field_val = array();
                 foreach ($inputs as $input) {
                     $field_val["input_{$input['id']}"] = RGFormsModel::get_parameter_value(rgar($input, 'name'), $field_values, $field);
                 }
             } elseif ($input_type == 'time') {
                 // maintained for backwards compatibility. The Time field now has an inputs array.
                 $parameter_val = RGFormsModel::get_parameter_value($field->inputName, $field_values, $field);
                 if (!empty($parameter_val) && preg_match('/^(\\d*):(\\d*) ?(.*)$/', $parameter_val, $matches)) {
                     $field_val = array();
                     $field_val[] = esc_attr($matches[1]);
                     //hour
                     $field_val[] = esc_attr($matches[2]);
                     //minute
                     $field_val[] = rgar($matches, 3);
                     //am or pm
                 }
             } elseif ($input_type == 'list') {
                 $parameter_val = RGFormsModel::get_parameter_value($field->inputName, $field_values, $field);
                 $field_val = is_array($parameter_val) ? $parameter_val : explode(',', str_replace('|', ',', $parameter_val));
                 if (is_array(rgar($field_val, 0))) {
                     $list_values = array();
                     foreach ($field_val as $row) {
                         $list_values = array_merge($list_values, array_values($row));
                     }
                     $field_val = $list_values;
                 }
             } else {
                 $field_val = RGFormsModel::get_parameter_value($field->inputName, $field_values, $field);
             }
         }
         //use default value if pre-populated value is empty
         $field_val = $field->get_value_default_if_empty($field_val);
         if (is_array($field->choices) && $input_type != 'list') {
             //radio buttons start at 0 and checkboxes start at 1
             $choice_index = $input_type == 'radio' ? 0 : 1;
             $is_pricing_field = GFCommon::is_pricing_field($field->type);
             foreach ($field->choices as $choice) {
                 if ($input_type == 'checkbox' && $choice_index % 10 == 0) {
                     $choice_index++;
                 }
                 $is_prepopulated = is_array($field_val) ? in_array($choice['value'], $field_val) : $choice['value'] == $field_val;
                 $is_choice_selected = rgar($choice, 'isSelected') || $is_prepopulated;
                 if ($is_choice_selected && $input_type == 'select') {
                     $price = GFCommon::to_number(rgar($choice, 'price')) == false ? 0 : GFCommon::to_number(rgar($choice, 'price'));
                     $val = $is_pricing_field && $field->type != 'quantity' ? $choice['value'] . '|' . $price : $choice['value'];
                     $default_values[$field->id] = $val;
                 } elseif ($is_choice_selected) {
                     if (!isset($default_values[$field->id])) {
                         $default_values[$field->id] = array();
                     }
                     $default_values[$field->id][] = "choice_{$form['id']}_{$field->id}_{$choice_index}";
//.........这里部分代码省略.........
开发者ID:timk85,项目名称:DIT,代码行数:101,代码来源:form_display.php

示例2: get_conditional_logic

 private static function get_conditional_logic($form, $field_values = array())
 {
     $logics = "";
     $dependents = "";
     $fields_with_logic = array();
     $default_values = array();
     foreach ($form["fields"] as $field) {
         //use section's logic if one exists
         $section = RGFormsModel::get_section($form, $field["id"]);
         $section_logic = !empty($section) ? rgar($section, "conditionalLogic") : null;
         $field_logic = $field["type"] != "page" ? RGForms::get("conditionalLogic", $field) : null;
         //page break conditional logic will be handled during the next button click
         $next_button_logic = isset($field["nextButton"]) && isset($field["nextButton"]["conditionalLogic"]) ? $field["nextButton"]["conditionalLogic"] : null;
         if (!empty($field_logic) || !empty($next_button_logic)) {
             $field_section_logic = array("field" => $field_logic, "nextButton" => $next_button_logic, "section" => $section_logic);
             $logics .= $field["id"] . ": " . GFCommon::json_encode($field_section_logic) . ",";
             $fields_with_logic[] = $field["id"];
             $peers = $field["type"] == "section" ? GFCommon::get_section_fields($form, $field["id"]) : array($field);
             $peer_ids = array();
             foreach ($peers as $peer) {
                 $peer_ids[] = $peer["id"];
             }
             $dependents .= $field["id"] . ": " . GFCommon::json_encode($peer_ids) . ",";
         }
         //-- Saving default values so that they can be restored when toggling conditional logic ---
         $field_val = "";
         $input_type = RGFormsModel::get_input_type($field);
         //get parameter value if pre-populate is enabled
         if (rgar($field, "allowsPrepopulate")) {
             if (is_array(rgar($field, "inputs"))) {
                 $field_val = array();
                 foreach ($field["inputs"] as $input) {
                     $field_val["input_{$input["id"]}"] = RGFormsModel::get_parameter_value(rgar($input, "name"), $field, $field_values);
                 }
             } else {
                 if ($input_type == "time") {
                     $parameter_val = RGFormsModel::get_parameter_value(rgar($field, "inputName"), $field, $field_values);
                     if (!empty($parameter_val) && preg_match('/^(\\d*):(\\d*) ?(.*)$/', $parameter_val, $matches)) {
                         $field_val = array();
                         $field_val[] = esc_attr($matches[1]);
                         //hour
                         $field_val[] = esc_attr($matches[2]);
                         //minute
                         $field_val[] = rgar($matches, 3);
                         //am or pm
                     }
                 } else {
                     if ($input_type == "list") {
                         $parameter_val = RGFormsModel::get_parameter_value(rgar($field, "inputName"), $field, $field_values);
                         $field_val = explode(",", str_replace("|", ",", $parameter_val));
                     } else {
                         $field_val = RGFormsModel::get_parameter_value(rgar($field, "inputName"), $field, $field_values);
                     }
                 }
             }
         }
         //use default value if pre-populated value is empty
         $field_val = self::default_if_empty($field, $field_val);
         if (is_array(rgar($field, "choices")) && $input_type != "list") {
             //radio buttons start at 0 and checkboxes start at 1
             $choice_index = $input_type == "radio" ? 0 : 1;
             foreach ($field["choices"] as $choice) {
                 if (rgar($choice, "isSelected") && $input_type == "select") {
                     $val = isset($choice["price"]) ? $choice["value"] . "|" . GFCommon::to_number($choice["price"]) : $choice["value"];
                     $default_values[$field["id"]] = $val;
                 } else {
                     if (rgar($choice, "isSelected")) {
                         if (!isset($default_values[$field["id"]])) {
                             $default_values[$field["id"]] = array();
                         }
                         $default_values[$field["id"]][] = "choice_{$field["id"]}_{$choice_index}";
                     }
                 }
                 $choice_index++;
             }
         } else {
             if (!empty($field_val)) {
                 $default_values[$field["id"]] = $field_val;
             }
         }
     }
     $button_conditional_script = "";
     //adding form button conditional logic if enabled
     if (isset($form["button"]["conditionalLogic"])) {
         $logics .= "0: " . GFCommon::json_encode(array("field" => $form["button"]["conditionalLogic"], "section" => null)) . ",";
         $dependents .= "0: " . GFCommon::json_encode(array(0)) . ",";
         $fields_with_logic[] = 0;
         $button_conditional_script = "jQuery('#gform_{$form['id']}').submit(" . "function(event, isButtonPress){" . "    var visibleButton = jQuery('.gform_next_button:visible, .gform_button:visible, .gform_image_button:visible');" . "    return visibleButton.length > 0 || isButtonPress == true;" . "}" . ");";
     }
     if (!empty($logics)) {
         $logics = substr($logics, 0, strlen($logics) - 1);
     }
     //removing last comma;
     if (!empty($dependents)) {
         $dependents = substr($dependents, 0, strlen($dependents) - 1);
     }
     //removing last comma;
     $animation = rgar($form, "enableAnimation") ? "1" : "0";
     global $wp_locale;
     $number_format = $wp_locale->number_format['decimal_point'] == "," ? "decimal_comma" : "decimal_dot";
//.........这里部分代码省略.........
开发者ID:pwillems,项目名称:mimosa-contents,代码行数:101,代码来源:form_display.php

示例3: get_conditional_logic

 private static function get_conditional_logic($form, $field_values = array())
 {
     $logics = '';
     $dependents = '';
     $fields_with_logic = array();
     $default_values = array();
     foreach ($form['fields'] as $field) {
         /* @var GF_Field $field */
         //use section's logic if one exists
         $section = RGFormsModel::get_section($form, $field->id);
         $section_logic = !empty($section) ? rgar($section, 'conditionalLogic') : null;
         $field_logic = $field->type != 'page' ? $field->conditionalLogic : null;
         //page break conditional logic will be handled during the next button click
         $next_button_logic = !empty($field->nextButton) && !empty($field->nextButton['conditionalLogic']) ? $field->nextButton['conditionalLogic'] : null;
         if (!empty($field_logic) || !empty($next_button_logic)) {
             $field_section_logic = array('field' => $field_logic, 'nextButton' => $next_button_logic, 'section' => $section_logic);
             $logics .= $field->id . ': ' . GFCommon::json_encode($field_section_logic) . ',';
             $fields_with_logic[] = $field->id;
             $peers = $field->type == 'section' ? GFCommon::get_section_fields($form, $field->id) : array($field);
             $peer_ids = array();
             foreach ($peers as $peer) {
                 $peer_ids[] = $peer->id;
             }
             $dependents .= $field->id . ': ' . GFCommon::json_encode($peer_ids) . ',';
         }
         //-- Saving default values so that they can be restored when toggling conditional logic ---
         $field_val = '';
         $input_type = RGFormsModel::get_input_type($field);
         //get parameter value if pre-populate is enabled
         if ($field->allowsPrepopulate) {
             if (is_array($field->inputs)) {
                 $field_val = array();
                 foreach ($field->inputs as $input) {
                     $field_val["input_{$input['id']}"] = RGFormsModel::get_parameter_value(rgar($input, 'name'), $field_values, $field);
                 }
             } else {
                 if ($input_type == 'time') {
                     // maintained for backwards compatibility. The Time field now has an inputs array.
                     $parameter_val = RGFormsModel::get_parameter_value($field->inputName, $field_values, $field);
                     if (!empty($parameter_val) && preg_match('/^(\\d*):(\\d*) ?(.*)$/', $parameter_val, $matches)) {
                         $field_val = array();
                         $field_val[] = esc_attr($matches[1]);
                         //hour
                         $field_val[] = esc_attr($matches[2]);
                         //minute
                         $field_val[] = rgar($matches, 3);
                         //am or pm
                     }
                 } else {
                     if ($input_type == 'list') {
                         $parameter_val = RGFormsModel::get_parameter_value($field->inputName, $field_values, $field);
                         $field_val = is_array($parameter_val) ? $parameter_val : explode(',', str_replace('|', ',', $parameter_val));
                     } else {
                         $field_val = RGFormsModel::get_parameter_value($field->inputName, $field_values, $field);
                     }
                 }
             }
         }
         //use default value if pre-populated value is empty
         $field_val = $field->get_value_default_if_empty($field_val);
         if (is_array($field->choices) && $input_type != 'list') {
             //radio buttons start at 0 and checkboxes start at 1
             $choice_index = $input_type == 'radio' ? 0 : 1;
             $is_pricing_field = GFCommon::is_pricing_field($field->type);
             foreach ($field->choices as $choice) {
                 if ($input_type == 'checkbox' && $choice_index % 10 == 0) {
                     $choice_index++;
                 }
                 if (rgar($choice, 'isSelected') && $input_type == 'select') {
                     $price = GFCommon::to_number(rgar($choice, 'price')) == false ? 0 : GFCommon::to_number(rgar($choice, 'price'));
                     $val = $is_pricing_field && $field->type != 'quantity' ? $choice['value'] . '|' . $price : $choice['value'];
                     $default_values[$field->id] = $val;
                 } else {
                     if (rgar($choice, 'isSelected')) {
                         if (!isset($default_values[$field->id])) {
                             $default_values[$field->id] = array();
                         }
                         $default_values[$field->id][] = "choice_{$form['id']}_{$field->id}_{$choice_index}";
                     }
                 }
                 $choice_index++;
             }
         } else {
             if (!empty($field_val)) {
                 if (GFFormsModel::get_input_type($field) == 'date') {
                     //format date
                     $format = empty($field->dateFormat) ? 'mdy' : esc_attr($field->dateFormat);
                     $date_info = GFcommon::parse_date($field_val, $format);
                     switch ($format) {
                         case 'mdy':
                             $field_val = $date_info['month'] . '/' . $date_info['day'] . '/' . $date_info['year'];
                             break;
                         case 'dmy':
                             $field_val = $date_info['day'] . '/' . $date_info['month'] . '/' . $date_info['year'];
                             break;
                         case 'ymd':
                             $field_val = $date_info['year'] . '/' . $date_info['month'] . '/' . $date_info['day'];
                             break;
                     }
                 }
//.........这里部分代码省略.........
开发者ID:sbayer55,项目名称:The-Road-Gallery,代码行数:101,代码来源:form_display.php


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