public static function choice_value_match($field, $choice, $value) { $choice_value = GFFormsModel::maybe_trim_input($choice['value'], $field->formId, $field); $value = GFFormsModel::maybe_trim_input($value, $field->formId, $field); $allowed_protocols = wp_kses_allowed_html('post'); $sanitized_value = wp_kses($value, $allowed_protocols); if ($choice_value == $value || $choice_value == $sanitized_value) { return true; } else { if ($field->enablePrice) { $ary = explode('|', $value); $val = count($ary) > 0 ? $ary[0] : ''; $sanitized_val = wp_kses($val, $allowed_protocols); $price = count($ary) > 1 ? $ary[1] : ''; if ($choice['value'] == $val || $choice['value'] == $sanitized_val) { return true; } } else { if (RGFormsModel::get_input_type($field) == 'multiselect') { $values = explode(',', $value); $sanitized_values = explode(',', $sanitized_value); if (in_array($choice_value, $values) || in_array($choice_value, $sanitized_values)) { return true; } } } } return false; }
public static function get_state($form, $field_values) { $product_fields = array(); foreach ($form['fields'] as $field) { /* @var GF_Field $field */ if (GFCommon::is_product_field($field->type) || $field->type == 'donation') { $value = RGFormsModel::get_field_value($field, $field_values, false); $value = $field->get_value_default_if_empty($value); switch ($field->inputType) { case 'calculation': case 'singleproduct': case 'hiddenproduct': $price = !is_array($value) || empty($value[$field->id . '.2']) ? $field->basePrice : $value[$field->id . '.2']; if (empty($price)) { $price = 0; } $price = GFCommon::to_number($price); $product_name = !is_array($value) || empty($value[$field->id . '.1']) ? $field->label : $value[$field->id . '.1']; $product_fields[$field->id . '.1'] = wp_hash(GFFormsModel::maybe_trim_input($product_name, $form['id'], $field)); $product_fields[$field->id . '.2'] = wp_hash(GFFormsModel::maybe_trim_input($price, $form['id'], $field)); break; case 'singleshipping': $price = !empty($value) ? $value : $field->basePrice; $price = !empty($price) ? GFCommon::to_number($price) : 0; $product_fields[$field->id] = wp_hash(GFFormsModel::maybe_trim_input($price, $form['id'], $field)); break; case 'radio': case 'select': $product_fields[$field->id] = array(); foreach ($field->choices as $choice) { $field_value = !empty($choice['value']) || $field->enableChoiceValue ? $choice['value'] : $choice['text']; if ($field->enablePrice) { $price = rgempty('price', $choice) ? 0 : GFCommon::to_number(rgar($choice, 'price')); $field_value .= '|' . $price; } $product_fields[$field->id][] = wp_hash(GFFormsModel::maybe_trim_input($field_value, $form['id'], $field)); } break; case 'checkbox': $index = 1; foreach ($field->choices as $choice) { $field_value = !empty($choice['value']) || $field->enableChoiceValue ? $choice['value'] : $choice['text']; if ($field->enablePrice) { $price = rgempty('price', $choice) ? 0 : GFCommon::to_number(rgar($choice, 'price')); $field_value .= '|' . $price; } if ($index % 10 == 0) { //hack to skip numbers ending in 0. so that 5.1 doesn't conflict with 5.10 $index++; } $product_fields[$field->id . '.' . $index++] = wp_hash(GFFormsModel::maybe_trim_input($field_value, $form['id'], $field)); } break; } } } $hash = json_encode($product_fields); $checksum = wp_hash(crc32($hash)); return base64_encode(json_encode(array($hash, $checksum))); }
/** * Retrieve the input value on submission. * * @param string $standard_name The input name used when accessing the $_POST. * @param string $custom_name The dynamic population parameter name. * @param array $field_values The dynamic population parameter names with their corresponding values to be populated. * @param bool|true $get_from_post_global_var Whether to get the value from the $_POST array as opposed to $field_values. * * @return array|string */ public function get_input_value_submission($standard_name, $custom_name = '', $field_values = array(), $get_from_post_global_var = true) { $form_id = $this->formId; if (!empty($_POST['is_submit_' . $form_id]) && $get_from_post_global_var) { $value = rgpost($standard_name); $value = GFFormsModel::maybe_trim_input($value, $form_id, $this); return $value; } elseif ($this->allowsPrepopulate) { return GFFormsModel::get_parameter_value($custom_name, $field_values, $this); } }
public static function choice_value_match($field, $choice, $value) { $choice_value = GFFormsModel::maybe_trim_input($choice['value'], $field->formId, $field); $value = GFFormsModel::maybe_trim_input($value, $field->formId, $field); if ($choice_value == $value) { return true; } else { if ($field->enablePrice) { $ary = explode('|', $value); $val = count($ary) > 0 ? $ary[0] : ''; $price = count($ary) > 1 ? $ary[1] : ''; if ($val == $choice['value']) { return true; } } else { if (RGFormsModel::get_input_type($field) == 'multiselect') { $values = explode(',', $value); if (in_array($choice_value, $values)) { return true; } } } } return false; }
public static function get_state($form, $field_values){ $product_fields = array(); foreach($form["fields"] as $field){ if(GFCommon::is_product_field($field["type"]) || $field["type"] == "donation"){ $value = RGFormsModel::get_field_value($field, $field_values, false); $value = self::default_if_empty($field, $value); switch($field["inputType"]){ case "calculation" : case "singleproduct" : case "hiddenproduct" : $price = !is_array($value) || empty($value[$field["id"] . ".2"]) ? $field["basePrice"] : $value[$field["id"] . ".2"]; if(empty($price)) $price = 0; $price = GFCommon::to_number($price); $product_name = !is_array($value) || empty($value[$field["id"] . ".1"]) ? $field["label"] : $value[$field["id"] . ".1"]; $product_fields[$field["id"]. ".1"] = wp_hash(GFFormsModel::maybe_trim_input($product_name, $form["id"], $field)); $product_fields[$field["id"]. ".2"] = wp_hash(GFFormsModel::maybe_trim_input($price, $form["id"], $field)); break; case "singleshipping" : $price = !empty($value) ? $value : $field["basePrice"]; $price = GFCommon::to_number($price); $product_fields[$field["id"]] = wp_hash(GFFormsModel::maybe_trim_input($price, $form["id"], $field)); break; case "radio" : case "select" : $product_fields[$field["id"]] = array(); foreach($field["choices"] as $choice){ $field_value = !empty($choice["value"]) || rgar($field,"enableChoiceValue") ? $choice["value"] : $choice["text"]; if($field["enablePrice"]) $field_value .= "|" . GFCommon::to_number(rgar($choice,"price")); $product_fields[$field["id"]][] = wp_hash(GFFormsModel::maybe_trim_input($field_value, $form["id"], $field)); } break; case "checkbox" : $index = 1; foreach($field["choices"] as $choice){ $field_value = !empty($choice["value"]) || $field["enableChoiceValue"] ? $choice["value"] : $choice["text"]; if($field["enablePrice"]) $field_value .= "|" . GFCommon::to_number(rgar($choice,"price")); if($index % 10 == 0) //hack to skip numbers ending in 0. so that 5.1 doesn't conflict with 5.10 $index++; $product_fields[$field["id"] . "." . $index++] = wp_hash(GFFormsModel::maybe_trim_input($field_value, $form["id"], $field)); } break; } } } $hash = json_encode($product_fields); $checksum = wp_hash(crc32($hash)); return base64_encode(json_encode(array($hash, $checksum))); }
public static function choice_value_match($field, $choice, $value) { $choice_value = GFFormsModel::maybe_trim_input($choice["value"], rgar($field, "formId"), $field); $value = GFFormsModel::maybe_trim_input($value, rgar($field, "formId"), $field); if ($choice_value == $value) { return true; } else { if (rgget("enablePrice", $field)) { $ary = explode("|", $value); $val = count($ary) > 0 ? $ary[0] : ""; $price = count($ary) > 1 ? $ary[1] : ""; if ($val == $choice["value"]) { return true; } } else { if (RGFormsModel::get_input_type($field) == 'multiselect') { $values = explode(',', $value); if (in_array($choice_value, $values)) { return true; } } } } return false; }