本文整理汇总了PHP中GFCommon::is_pricing_field方法的典型用法代码示例。如果您正苦于以下问题:PHP GFCommon::is_pricing_field方法的具体用法?PHP GFCommon::is_pricing_field怎么用?PHP GFCommon::is_pricing_field使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类GFCommon
的用法示例。
在下文中一共展示了GFCommon::is_pricing_field方法的8个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: save_lead
public static function save_lead($form, &$lead)
{
global $wpdb;
GFCommon::log_debug(__METHOD__ . '(): Saving entry.');
$is_form_editor = GFCommon::is_form_editor();
$is_entry_detail = GFCommon::is_entry_detail();
$is_admin = $is_form_editor || $is_entry_detail;
if ($is_admin && !GFCommon::current_user_can_any('gravityforms_edit_entries')) {
die(esc_html__("You don't have adequate permission to edit entries.", 'gravityforms'));
}
$lead_detail_table = self::get_lead_details_table_name();
$is_new_lead = $lead == null;
//Inserting lead if null
if ($is_new_lead) {
global $current_user;
$user_id = $current_user && $current_user->ID ? $current_user->ID : 'NULL';
$lead_table = RGFormsModel::get_lead_table_name();
$user_agent = self::truncate($_SERVER['HTTP_USER_AGENT'], 250);
$currency = GFCommon::get_currency();
$source_url = self::truncate(self::get_current_page_url(), 200);
$wpdb->query($wpdb->prepare("INSERT INTO {$lead_table}(form_id, ip, source_url, date_created, user_agent, currency, created_by) VALUES(%d, %s, %s, utc_timestamp(), %s, %s, {$user_id})", $form['id'], self::get_ip(), $source_url, $user_agent, $currency));
//reading newly created lead id
$lead_id = $wpdb->insert_id;
$lead = array('id' => $lead_id);
GFCommon::log_debug(__METHOD__ . "(): Entry record created in the database. ID: {$lead_id}.");
}
$current_fields = $wpdb->get_results($wpdb->prepare("SELECT id, field_number FROM {$lead_detail_table} WHERE lead_id=%d", $lead['id']));
$total_fields = array();
/* @var $calculation_fields GF_Field[] */
$calculation_fields = array();
$recalculate_total = false;
GFCommon::log_debug(__METHOD__ . '(): Saving entry fields.');
foreach ($form['fields'] as $field) {
/* @var $field GF_Field */
// ignore the honeypot field
if ($field->type == 'honeypot') {
continue;
}
//Ignore fields that are marked as display only
if ($field->displayOnly && $field->type != 'password') {
continue;
}
//ignore pricing fields in the entry detail
if (RG_CURRENT_VIEW == 'entry' && GFCommon::is_pricing_field($field->type)) {
continue;
}
//process total field after all fields have been saved
if ($field->type == 'total') {
$total_fields[] = $field;
continue;
}
$is_entry_update = RG_CURRENT_VIEW == 'entry' || !$is_new_lead;
$read_value_from_post = $is_new_lead || !isset($lead['date_created']);
//only save fields that are not hidden (except when updating an entry)
if ($is_entry_update || !GFFormsModel::is_field_hidden($form, $field, array(), $read_value_from_post ? null : $lead)) {
// process calculation fields after all fields have been saved (moved after the is hidden check)
if ($field->has_calculation()) {
$calculation_fields[] = $field;
continue;
}
if ($field->type == 'post_category') {
$field = GFCommon::add_categories_as_choices($field, '');
}
$inputs = $field->get_entry_inputs();
if (is_array($inputs)) {
foreach ($inputs as $input) {
self::save_input($form, $field, $lead, $current_fields, $input['id']);
}
} else {
self::save_input($form, $field, $lead, $current_fields, $field->id);
}
}
}
if (!empty($calculation_fields)) {
foreach ($calculation_fields as $calculation_field) {
$inputs = $calculation_field->get_entry_inputs();
if (is_array($inputs)) {
foreach ($inputs as $input) {
self::save_input($form, $calculation_field, $lead, $current_fields, $input['id']);
self::refresh_lead_field_value($lead['id'], $input['id']);
}
} else {
self::save_input($form, $calculation_field, $lead, $current_fields, $calculation_field->id);
self::refresh_lead_field_value($lead['id'], $calculation_field->id);
}
}
self::refresh_product_cache($form, $lead = RGFormsModel::get_lead($lead['id']));
}
//saving total field as the last field of the form.
if (!empty($total_fields)) {
foreach ($total_fields as $total_field) {
self::save_input($form, $total_field, $lead, $current_fields, $total_field->id);
self::refresh_lead_field_value($lead['id'], $total_field['id']);
}
}
GFCommon::log_debug(__METHOD__ . '(): Finished saving entry fields.');
}
示例2: save_lead
public static function save_lead($form, &$lead)
{
global $wpdb;
if (IS_ADMIN && !GFCommon::current_user_can_any("gravityforms_edit_entries")) {
die(__("You don't have adequate permission to edit entries.", "gravityforms"));
}
$lead_detail_table = self::get_lead_details_table_name();
//Inserting lead if null
if ($lead == null) {
global $current_user;
$user_id = $current_user && $current_user->ID ? $current_user->ID : 'NULL';
$lead_table = RGFormsModel::get_lead_table_name();
$user_agent = strlen($_SERVER["HTTP_USER_AGENT"]) > 250 ? substr($_SERVER["HTTP_USER_AGENT"], 0, 250) : $_SERVER["HTTP_USER_AGENT"];
$currency = GFCommon::get_currency();
$wpdb->query($wpdb->prepare("INSERT INTO {$lead_table}(form_id, ip, source_url, date_created, user_agent, currency, created_by) VALUES(%d, %s, %s, utc_timestamp(), %s, %s, {$user_id})", $form["id"], self::get_ip(), self::get_current_page_url(), $user_agent, $currency));
//reading newly created lead id
$lead_id = $wpdb->insert_id;
$lead = array("id" => $lead_id);
}
$current_fields = $wpdb->get_results($wpdb->prepare("SELECT id, field_number FROM {$lead_detail_table} WHERE lead_id=%d", $lead["id"]));
$original_post_id = rgget("post_id", $lead);
$total_field = null;
$calculation_fields = array();
$recalculate_total = false;
foreach ($form["fields"] as $field) {
//Ignore fields that are marked as display only
if (rgget("displayOnly", $field) && $field["type"] != "password") {
continue;
}
//ignore pricing fields in the entry detail
if (RG_CURRENT_VIEW == "entry" && GFCommon::is_pricing_field($field["type"])) {
continue;
}
//process total field after all fields have been saved
if ($field["type"] == "total") {
$total_field = $field;
continue;
}
//only save fields that are not hidden (except on entry screen)
if (RG_CURRENT_VIEW == "entry" || !RGFormsModel::is_field_hidden($form, $field, array())) {
// process calculation fields after all fields have been saved
if (GFCommon::has_field_calculation($field)) {
$calculation_fields[] = $field;
continue;
}
if ($field['type'] == 'post_category') {
$field = GFCommon::add_categories_as_choices($field, '');
}
if (isset($field["inputs"]) && is_array($field["inputs"])) {
foreach ($field["inputs"] as $input) {
self::save_input($form, $field, $lead, $current_fields, $input["id"]);
}
} else {
self::save_input($form, $field, $lead, $current_fields, $field["id"]);
}
}
}
if (!empty($calculation_fields)) {
foreach ($calculation_fields as $calculation_field) {
if (isset($calculation_field["inputs"]) && is_array($calculation_field["inputs"])) {
foreach ($calculation_field["inputs"] as $input) {
self::save_input($form, $calculation_field, $lead, $current_fields, $input["id"]);
}
} else {
self::save_input($form, $calculation_field, $lead, $current_fields, $calculation_field["id"]);
}
}
self::refresh_product_cache($form, $lead = RGFormsModel::get_lead($lead['id']));
}
//saving total field as the last field of the form.
if ($total_field) {
self::save_input($form, $total_field, $lead, $current_fields, $total_field["id"]);
}
}
示例3: 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}";
//.........这里部分代码省略.........
示例4: 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;
}
}
//.........这里部分代码省略.........
示例5: 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_values, $field);
}
} else {
if ($input_type == "time") {
$parameter_val = RGFormsModel::get_parameter_value(rgar($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(rgar($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(rgar($field, "inputName"), $field_values, $field);
}
}
}
}
//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;
$is_pricing_field = GFCommon::is_pricing_field($field['type']);
foreach ($field["choices"] as $choice) {
if (rgar($choice, "isSelected") && $input_type == "select") {
$val = $is_pricing_field ? $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)) {
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;
}
}
$default_values[$field["id"]] = $field_val;
}
}
}
$button_conditional_script = "";
//adding form button conditional logic if enabled
//.........这里部分代码省略.........
示例6: save_lead
public static function save_lead($form, &$lead)
{
global $wpdb;
if (IS_ADMIN && !GFCommon::current_user_can_any("gravityforms_edit_entries")) {
die(__("You don't have adequate permission to edit entries.", "gravityforms"));
}
$lead_detail_table = self::get_lead_details_table_name();
//Inserting lead if null
if ($lead == null) {
global $current_user;
$user_id = $current_user && $current_user->ID ? $current_user->ID : 'NULL';
$lead_table = RGFormsModel::get_lead_table_name();
$user_agent = strlen($_SERVER["HTTP_USER_AGENT"]) > 250 ? substr($_SERVER["HTTP_USER_AGENT"], 0, 250) : $_SERVER["HTTP_USER_AGENT"];
$currency = GFCommon::get_currency();
$wpdb->query($wpdb->prepare("INSERT INTO {$lead_table}(form_id, ip, source_url, date_created, user_agent, currency, created_by) VALUES(%d, %s, %s, utc_timestamp(), %s, %s, {$user_id})", $form["id"], self::get_ip(), self::get_current_page_url(), $user_agent, $currency));
//reading newly created lead id
$lead_id = $wpdb->insert_id;
$lead = array("id" => $lead_id);
}
$current_fields = $wpdb->get_results($wpdb->prepare("SELECT id, field_number FROM {$lead_detail_table} WHERE lead_id=%d", $lead["id"]));
$original_post_id = $lead["post_id"];
foreach ($form["fields"] as $field) {
//Ignore fields that are marked as display only
if ($field["displayOnly"] && $field["type"] != "password") {
continue;
}
//ignore pricing fields in the entry detail
if (RG_CURRENT_VIEW == "entry" && GFCommon::is_pricing_field($field["type"])) {
continue;
}
//only save fields that are not hidden (except on entry screen)
if (RG_CURRENT_VIEW == "entry" || !RGFormsModel::is_field_hidden($form, $field, array())) {
if (is_array($field["inputs"])) {
foreach ($field["inputs"] as $input) {
self::save_input($form, $field, $lead, $current_fields, $input["id"]);
}
} else {
self::save_input($form, $field, $lead, $current_fields, $field["id"]);
}
}
}
}
示例7: save_entry
public function save_entry($form, &$lead, $editable_fields)
{
global $wpdb;
gravity_flow()->log_debug(__METHOD__ . '(): Saving entry.');
$lead_detail_table = GFFormsModel::get_lead_details_table_name();
$is_new_lead = $lead == null;
// Bailing if null
if ($is_new_lead) {
return;
}
$current_fields = $wpdb->get_results($wpdb->prepare("SELECT id, field_number FROM {$lead_detail_table} WHERE lead_id=%d", $lead['id']));
$total_fields = array();
/* @var $calculation_fields GF_Field[] */
$calculation_fields = array();
$recalculate_total = false;
GFCommon::log_debug(__METHOD__ . '(): Saving entry fields.');
foreach ($form['fields'] as &$field) {
/* @var $field GF_Field */
//Ignore fields that are marked as display only
if ($field->displayOnly && $field->type != 'password') {
continue;
}
//ignore pricing fields in the entry detail
if (RG_CURRENT_VIEW == 'entry' && GFCommon::is_pricing_field($field->type)) {
//continue;
}
//process total field after all fields have been saved
if ($field->type == 'total') {
$total_fields[] = $field;
continue;
}
// process calculation fields after all fields have been saved (moved after the is hidden check)
if ($field->has_calculation()) {
$calculation_fields[] = $field;
continue;
}
if (!in_array($field->id, $editable_fields)) {
continue;
}
if (!$this->conditional_logic_editable_fields_enabled) {
$field->conditionalLogic = null;
}
gravity_flow()->log_debug(__METHOD__ . "(): Saving field {$field->label}(#{$field->id} - {$field->type}).");
if ($field->type == 'post_category') {
$field = GFCommon::add_categories_as_choices($field, '');
}
$inputs = $field->get_entry_inputs();
if (is_array($inputs)) {
foreach ($inputs as $input) {
GFFormsModel::save_input($form, $field, $lead, $current_fields, $input['id']);
}
} else {
GFFormsModel::save_input($form, $field, $lead, $current_fields, $field->id);
}
}
if (!empty($calculation_fields)) {
foreach ($calculation_fields as $calculation_field) {
gravity_flow()->log_debug(__METHOD__ . "(): Saving calculated field {$calculation_field->label}(#{$calculation_field->id} - {$calculation_field->type}).");
// Make sure that the value gets recalculated
$calculation_field->conditionalLogic = null;
$inputs = $calculation_field->get_entry_inputs();
if (is_array($inputs)) {
if (!in_array($calculation_field->id, $editable_fields)) {
// Make sure calculated product names and quantities are saved as if they're submitted.
$value = array($calculation_field->id . '.1' => $lead[$calculation_field->id . '.1']);
$_POST['input_' . $calculation_field->id . '_1'] = $calculation_field->get_field_label(false, $value);
$quantity = trim($lead[$calculation_field->id . '.3']);
if ($calculation_field->disableQuantity && empty($quantity)) {
$_POST['input_' . $calculation_field->id . '_3'] = 1;
} else {
$_POST['input_' . $calculation_field->id . '_3'] = $quantity;
}
}
foreach ($inputs as $input) {
GFFormsModel::save_input($form, $calculation_field, $lead, $current_fields, $input['id']);
GFFormsModel::refresh_lead_field_value($lead['id'], $input['id']);
}
} else {
GFFormsModel::save_input($form, $calculation_field, $lead, $current_fields, $calculation_field->id);
GFFormsModel::refresh_lead_field_value($lead['id'], $calculation_field->id);
}
}
}
GFFormsModel::refresh_product_cache($form, $lead = RGFormsModel::get_lead($lead['id']));
//saving total field as the last field of the form.
if (!empty($total_fields)) {
foreach ($total_fields as $total_field) {
gravity_flow()->log_debug(__METHOD__ . '(): Saving total field.');
GFFormsModel::save_input($form, $total_field, $lead, $current_fields, $total_field->id);
GFFormsModel::refresh_lead_field_value($lead['id'], $total_field->id);
}
}
}
示例8: get_form_fields
public static function get_form_fields($form)
{
$str = "<option value=''>" . __("Insert merge code", "gravityforms") . "</option>";
$required_fields = array();
$optional_fields = array();
$pricing_fields = array();
foreach ($form["fields"] as $field) {
if ($field["displayOnly"]) {
continue;
}
$input_type = RGFormsModel::get_input_type($field);
//skip field types that should be excluded
if (is_array($exclude) && in_array($input_type, $exclude)) {
continue;
}
if ($field["isRequired"]) {
switch ($input_type) {
case "name":
if ($field["nameFormat"] == "extended") {
$prefix = GFCommon::get_input($field, $field["id"] + 0.2);
$suffix = GFCommon::get_input($field, $field["id"] + 0.8);
$optional_field = $field;
$optional_field["inputs"] = array($prefix, $suffix);
//Add optional name fields to the optional list
$optional_fields[] = $optional_field;
//Remove optional name field from required list
unset($field["inputs"][0]);
unset($field["inputs"][3]);
}
$required_fields[] = $field;
break;
default:
$required_fields[] = $field;
}
} else {
$optional_fields[] = $field;
}
if (GFCommon::is_pricing_field($field["type"])) {
$pricing_fields[] = $field;
}
}
if (!empty($required_fields)) {
$str .= "<optgroup label='" . __("Required form fields", "gravityforms") . "'>";
foreach ($required_fields as $field) {
$str .= self::get_field_variable($field);
}
$str .= "</optgroup>";
}
if (!empty($optional_fields)) {
$str .= "<optgroup label='" . __("Optional form fields", "gravityforms") . "'>";
foreach ($optional_fields as $field) {
$str .= self::get_field_variable($field);
}
$str .= "</optgroup>";
}
if (!empty($pricing_fields)) {
$str .= "<optgroup label='" . __("Pricing form fields", "gravityforms") . "'>";
foreach ($pricing_fields as $field) {
$str .= self::get_field_variable($field);
}
$str .= "</optgroup>";
}
$str .= "<optgroup label='" . __("Other", "gravityforms") . "'>\n <option value='{ip}'>" . __("Client IP Address", "gravityforms") . "</option>\n <option value='{date_mdy}'>" . __("Date", "gravityforms") . " (mm/dd/yyyy)</option>\n <option value='{date_dmy}'>" . __("Date", "gravityforms") . " (dd/mm/yyyy)</option>\n <option value='{embed_post:ID}'>" . __("Embed Post/Page Id", "gravityforms") . "</option>\n <option value='{embed_post:post_title}'>" . __("Embed Post/Page Title", "gravityforms") . "</option>\n <option value='{embed_url}'>" . __("Embed URL", "gravityforms") . "</option>\n <option value='{entry_id}'>" . __("Entry Id", "gravityforms") . "</option>\n <option value='{entry_url}'>" . __("Entry URL", "gravityforms") . "</option>\n <option value='{form_id}'>" . __("Form Id", "gravityforms") . "</option>\n <option value='{form_title}'>" . __("Form Title", "gravityforms") . "</option>\n <option value='{user_agent}'>" . __("HTTP User Agent", "gravityforms") . "</option>";
if (GFCommon::has_post_field($form["fields"])) {
$str .= "<option value='{post_id}'>" . __("Post Id", "gravityforms") . "</option>\n <option value='{post_edit_url}'>" . __("Post Edit URL", "gravityforms") . "</option>";
}
$str .= "<option value='{user:display_name}'>" . __("User Display Name", "gravityforms") . "</option>\n <option value='{user:user_email}'>" . __("User Email", "gravityforms") . "</option>\n <option value='{user:user_login}'>" . __("User Login", "gravityforms") . "</option>\n </optgroup>";
return $str;
}