本文整理汇总了PHP中GFCommon::add_categories_as_choices方法的典型用法代码示例。如果您正苦于以下问题:PHP GFCommon::add_categories_as_choices方法的具体用法?PHP GFCommon::add_categories_as_choices怎么用?PHP GFCommon::add_categories_as_choices使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类GFCommon
的用法示例。
在下文中一共展示了GFCommon::add_categories_as_choices方法的9个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: get_post_fields
private static function get_post_fields($form, $lead)
{
$post_data = array();
$post_data["post_custom_fields"] = array();
$post_data["tags_input"] = array();
$categories = array();
$images = array();
foreach ($form["fields"] as $field) {
if ($field['type'] == 'post_category') {
$field = GFCommon::add_categories_as_choices($field, '');
}
$value = self::get_post_field_value($field, $lead);
switch ($field["type"]) {
case "post_title":
case "post_excerpt":
case "post_content":
$post_data[$field["type"]] = $value;
break;
case "post_tags":
$tags = explode(",", $value);
if (is_array($tags) && sizeof($tags) > 0) {
$post_data["tags_input"] = array_merge($post_data["tags_input"], $tags);
}
break;
case "post_custom_field":
$meta_name = $field["postCustomFieldName"];
if (!isset($post_data["post_custom_fields"][$meta_name])) {
$post_data["post_custom_fields"][$meta_name] = $value;
} else {
if (!is_array($post_data["post_custom_fields"][$meta_name])) {
$post_data["post_custom_fields"][$meta_name] = array($post_data["post_custom_fields"][$meta_name], $value);
} else {
$post_data["post_custom_fields"][$meta_name][] = $value;
}
}
break;
case "post_category":
foreach (explode(',', $value) as $cat_string) {
list($cat_name, $cat_id) = rgexplode(":", $cat_string, 2);
array_push($categories, $cat_id);
}
break;
case "post_image":
$ary = !empty($value) ? explode("|:|", $value) : array();
$url = count($ary) > 0 ? $ary[0] : "";
$title = count($ary) > 1 ? $ary[1] : "";
$caption = count($ary) > 2 ? $ary[2] : "";
$description = count($ary) > 3 ? $ary[3] : "";
array_push($images, array("field_id" => $field["id"], "url" => $url, "title" => $title, "description" => $description, "caption" => $caption));
break;
}
}
$post_data["post_status"] = rgar($form, "postStatus");
$post_data["post_category"] = !empty($categories) ? $categories : array(rgar($form, 'postCategory'));
$post_data["images"] = $images;
//setting current user as author depending on settings
$post_data["post_author"] = $form["useCurrentUserAsAuthor"] && !empty($lead["created_by"]) ? $lead["created_by"] : $form["postAuthor"];
return $post_data;
}
示例2: get_grid_columns
public static function get_grid_columns($form_id, $input_label_only = false)
{
$form = self::get_form_meta($form_id);
$field_ids = self::get_grid_column_meta($form_id);
if (!is_array($field_ids)) {
$field_ids = array();
for ($i = 0, $count = sizeof($form['fields']); $i < $count && $i < 5; $i++) {
/* @var GF_Field $field */
$field = $form['fields'][$i];
//loading post category fields with choices and inputs
if ($field->type == 'post_category') {
$field = GFCommon::add_categories_as_choices($field, '');
}
if (RGForms::get('displayOnly', $field) || self::get_input_type($field) == 'list') {
continue;
}
$inputs = $field->get_entry_inputs();
if (is_array($inputs)) {
if ($field->type == 'name') {
$field_ids[] = $field->id . '.3';
//adding first name
$field_ids[] = $field->id . '.6';
//adding last name
} else {
$field_ids[] = $field->inputs[0]['id'];
//getting first input
}
} else {
$field_ids[] = $field->id;
}
}
//adding default entry meta columns
$entry_metas = GFFormsModel::get_entry_meta($form_id);
foreach ($entry_metas as $key => $entry_meta) {
if (rgar($entry_meta, 'is_default_column')) {
$field_ids[] = $key;
}
}
}
$columns = array();
$entry_meta = self::get_entry_meta($form_id);
foreach ($field_ids as $field_id) {
switch ($field_id) {
case 'id':
$columns[$field_id] = array('label' => esc_html__('Entry Id', 'gravityforms'), 'type' => 'id');
break;
case 'ip':
$columns[$field_id] = array('label' => esc_html__('User IP', 'gravityforms'), 'type' => 'ip');
break;
case 'date_created':
$columns[$field_id] = array('label' => esc_html__('Entry Date', 'gravityforms'), 'type' => 'date_created');
break;
case 'source_url':
$columns[$field_id] = array('label' => esc_html__('Source Url', 'gravityforms'), 'type' => 'source_url');
break;
case 'payment_status':
$columns[$field_id] = array('label' => esc_html__('Payment Status', 'gravityforms'), 'type' => 'payment_status');
break;
case 'transaction_id':
$columns[$field_id] = array('label' => esc_html__('Transaction Id', 'gravityforms'), 'type' => 'transaction_id');
break;
case 'payment_date':
$columns[$field_id] = array('label' => esc_html__('Payment Date', 'gravityforms'), 'type' => 'payment_date');
break;
case 'payment_amount':
$columns[$field_id] = array('label' => esc_html__('Payment Amount', 'gravityforms'), 'type' => 'payment_amount');
break;
case 'created_by':
$columns[$field_id] = array('label' => esc_html__('User', 'gravityforms'), 'type' => 'created_by');
break;
case (is_string($field_id) || is_int($field_id)) && array_key_exists($field_id, $entry_meta):
$columns[$field_id] = array('label' => $entry_meta[$field_id]['label'], 'type' => $field_id);
break;
default:
$field = self::get_field($form, $field_id);
if ($field) {
$input_label_only = apply_filters('gform_entry_list_column_input_label_only', $input_label_only, $form, $field);
$columns[strval($field_id)] = array('label' => self::get_label($field, $field_id, $input_label_only), 'type' => $field->type, 'inputType' => $field->inputType);
}
}
}
return $columns;
}
示例3: modify_edit_field_input
/**
*
* Fill-in the saved values into the form inputs
*
* @param string $field_content Always empty.
* @param GF_Field $field
* @param string|array $value If array, it's a field with multiple inputs. If string, single input.
* @param int $lead_id Lead ID. Always 0 for the `gform_field_input` filter.
* @param int $form_id Form ID
*
* @return mixed
*/
function modify_edit_field_input($field_content = '', $field, $value, $lead_id = 0, $form_id)
{
// If the form has been submitted, then we don't need to pre-fill the values,
// Except for fileupload type - run always!!
if ($this->is_edit_entry_submission() && 'fileupload' !== $field->type || GFCommon::is_product_field($field->type)) {
return $field_content;
}
// Turn on Admin-style display for file upload fields only
if ('fileupload' === $field->type) {
$_GET['page'] = 'gf_entries';
}
// SET SOME FIELD DEFAULTS TO PREVENT ISSUES
$field->adminOnly = false;
/** @see GFFormDisplay::get_counter_init_script() need to prevent adminOnly */
// add categories as choices for Post Category field
if ('post_category' === $field->type) {
$field = GFCommon::add_categories_as_choices($field, $value);
}
/**
* @filter `gravityview/edit_entry/pre_populate/override` Allow the pre-populated value to override saved value in Edit Entry form. By default, pre-populate mechanism only kicks on empty fields.
* @param boolean True: override saved values; False: don't override (default)
* @param $field GF_Field object Gravity Forms field object
* @since 1.13
*/
$override_saved_value = apply_filters('gravityview/edit_entry/pre_populate/override', false, $field);
// We're dealing with multiple inputs (e.g. checkbox) but not time or date (as it doesn't store data in input IDs)
if (isset($field->inputs) && is_array($field->inputs) && !in_array($field->type, array('time', 'date'))) {
$field_value = array();
// only accept pre-populated values if the field doesn't have any choice selected.
$allow_pre_populated = $field->allowsPrepopulate;
foreach ((array) $field->inputs as $input) {
$input_id = strval($input['id']);
if (!empty($this->entry[$input_id])) {
$field_value[$input_id] = 'post_category' === $field->type ? GFCommon::format_post_category($this->entry[$input_id], true) : $this->entry[$input_id];
$allow_pre_populated = false;
}
}
$pre_value = $field->get_value_submission(array(), false);
$field_value = !$allow_pre_populated && !($override_saved_value && !empty($pre_value)) ? $field_value : $pre_value;
} else {
$id = intval($field->id);
// get pre-populated value if exists
$pre_value = $field->allowsPrepopulate ? GFFormsModel::get_parameter_value($field->inputName, array(), $field) : '';
// saved field entry value (if empty, fallback to the pre-populated value, if exists)
// or pre-populated value if not empty and set to override saved value
$field_value = !empty($this->entry[$id]) && !($override_saved_value && !empty($pre_value)) ? $this->entry[$id] : $pre_value;
// in case field is post_category but inputType is select, multi-select or radio, convert value into array of category IDs.
if ('post_category' === $field->type && !empty($field_value)) {
$categories = array();
foreach (explode(',', $field_value) as $cat_string) {
$categories[] = GFCommon::format_post_category($cat_string, true);
}
$field_value = 'multiselect' === $field->get_input_type() ? $categories : implode('', $categories);
}
}
// if value is empty get the default value if defined
$field_value = $field->get_value_default_if_empty($field_value);
/**
* @filter `gravityview/edit_entry/field_value` Change the value of an Edit Entry field, if needed
* @since 1.11
* @param mixed $field_value field value used to populate the input
* @param object $field Gravity Forms field object ( Class GF_Field )
*/
$field_value = apply_filters('gravityview/edit_entry/field_value', $field_value, $field);
// Prevent any PHP warnings, like undefined index
ob_start();
$return = $field->get_field_input($this->form, $field_value, $this->entry);
// If there was output, it's an error
$warnings = ob_get_clean();
if (!empty($warnings)) {
do_action('gravityview_log_error', __METHOD__ . $warnings, $field_value);
}
/**
* Unset hack $_GET['page'] = 'gf_entries'
* We need the fileupload html field to render with the proper id
* ( <li id="field_80_16" ... > )
*/
unset($_GET['page']);
return $return;
}
示例4: get_grid_columns
public static function get_grid_columns($form_id, $input_label_only = false)
{
$form = self::get_form_meta($form_id);
$field_ids = self::get_grid_column_meta($form_id);
if (!is_array($field_ids)) {
$field_ids = array();
for ($i = 0, $count = sizeof($form["fields"]); $i < $count && $i < 5; $i++) {
$field = $form["fields"][$i];
//loading post category fields with choices and inputs
if ($field["type"] == "post_category") {
$field = GFCommon::add_categories_as_choices($field, "");
}
if (RGForms::get("displayOnly", $field) || self::get_input_type($field) == "list") {
continue;
}
if (isset($field["inputs"]) && is_array($field["inputs"])) {
if ($field["type"] == "name") {
$field_ids[] = $field["id"] . '.3';
//adding first name
$field_ids[] = $field["id"] . '.6';
//adding last name
} else {
$field_ids[] = $field["inputs"][0]["id"];
//getting first input
}
} else {
$field_ids[] = $field["id"];
}
}
//adding default entry meta columns
$entry_metas = GFFormsModel::get_entry_meta($form_id);
foreach ($entry_metas as $key => $entry_meta) {
if (rgar($entry_meta, "is_default_column")) {
$field_ids[] = $key;
}
}
}
$columns = array();
$entry_meta = self::get_entry_meta($form_id);
foreach ($field_ids as $field_id) {
switch ($field_id) {
case "id":
$columns[$field_id] = array("label" => "Entry Id", "type" => "id");
break;
case "ip":
$columns[$field_id] = array("label" => "User IP", "type" => "ip");
break;
case "date_created":
$columns[$field_id] = array("label" => "Entry Date", "type" => "date_created");
break;
case "source_url":
$columns[$field_id] = array("label" => "Source Url", "type" => "source_url");
break;
case "payment_status":
$columns[$field_id] = array("label" => "Payment Status", "type" => "payment_status");
break;
case "transaction_id":
$columns[$field_id] = array("label" => "Transaction Id", "type" => "transaction_id");
break;
case "payment_date":
$columns[$field_id] = array("label" => "Payment Date", "type" => "payment_date");
break;
case "payment_amount":
$columns[$field_id] = array("label" => "Payment Amount", "type" => "payment_amount");
break;
case "created_by":
$columns[$field_id] = array("label" => "User", "type" => "created_by");
break;
case (is_string($field_id) || is_int($field_id)) && array_key_exists($field_id, $entry_meta):
$columns[$field_id] = array("label" => $entry_meta[$field_id]["label"], "type" => $field_id);
break;
default:
$field = self::get_field($form, $field_id);
if ($field) {
$columns[strval($field_id)] = array("label" => self::get_label($field, $field_id, $input_label_only), "type" => rgget("type", $field), "inputType" => rgget("inputType", $field));
}
}
}
return $columns;
}
示例5: save_lead
/**
* Adapted from forms_model.php, RGFormsModel::save_lead($Form, $lead)
* @param array $form Form object.
* @param array $lead Lead object
* @return void
*/
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 = RGFormsModel::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 = RGFormsModel::truncate($_SERVER["HTTP_USER_AGENT"], 250);
$currency = GFCommon::get_currency();
$source_url = RGFormsModel::truncate(RGFormsModel::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"], RGFormsModel::get_ip(), $source_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_fields = array();
$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_fields[] = $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(), $lead)) {
// process calculation fields after all fields have been saved (moved after the is hidden check)
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) {
RGFormsModel::save_input($form, $field, $lead, $current_fields, $input["id"]);
}
} else {
RGFormsModel::save_input($form, $field, $lead, $current_fields, $field["id"]);
}
}
//Refresh lead to support conditionals (not optimal but...)
$lead = RGFormsModel::get_lead($lead['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) {
RGFormsModel::save_input($form, $calculation_field, $lead, $current_fields, $input["id"]);
RGFormsModel::refresh_lead_field_value($lead["id"], $input["id"]);
}
} else {
RGFormsModel::save_input($form, $calculation_field, $lead, $current_fields, $calculation_field["id"]);
RGFormsModel::refresh_lead_field_value($lead["id"], $calculation_field["id"]);
}
}
RGFormsModel::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) {
GFCommon::log_debug("Saving total field.");
RGFormsModel::save_input($form, $total_field, $lead, $current_fields, $total_field["id"]);
}
}
}
示例6: 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);
}
}
}
示例7: get_field_input
/**
* @param GF_Field $field
* @param string $value
* @param int $lead_id
* @param int $form_id
* @param null $form
*
* @return mixed|string|void
*/
public static function get_field_input($field, $value = '', $lead_id = 0, $form_id = 0, $form = null)
{
if (!$field instanceof GF_Field) {
$field = GF_Fields::create($field);
}
$field->adminOnly = false;
$id = intval($field->id);
$field_id = 'input_' . $form_id . "_{$id}";
$entry = RGFormsModel::get_lead($lead_id);
$post_id = $entry['post_id'];
$post_link = '';
if (is_numeric($post_id) && GFCommon::is_post_field($field)) {
$post_link = "<div>You can <a href='post.php?action=edit&post={$post_id}'>edit this post</a> from the post page.</div>";
}
$field_input = apply_filters('gform_field_input', '', $field, $value, $lead_id, $form_id);
if ($field_input) {
return $field_input;
}
// add categories as choices for Post Category field
if ($field->type == 'post_category') {
$field = GFCommon::add_categories_as_choices($field, $value);
}
$type = RGFormsModel::get_input_type($field);
switch ($type) {
case 'honeypot':
$autocomplete = RGFormsModel::is_html5_enabled() ? "autocomplete='off'" : '';
return "<div class='ginput_container'><input name='input_{$id}' id='{$field_id}' type='text' value='' {$autocomplete}/></div>";
break;
case 'adminonly_hidden':
if (!is_array($field->inputs)) {
if (is_array($value)) {
$value = json_encode($value);
}
return sprintf("<input name='input_%d' id='%s' class='gform_hidden' type='hidden' value='%s'/>", $id, $field_id, esc_attr($value));
}
$fields = '';
foreach ($field->inputs as $input) {
$fields .= sprintf("<input name='input_%s' class='gform_hidden' type='hidden' value='%s'/>", $input['id'], esc_attr(rgar($value, strval($input['id']))));
}
return $fields;
break;
default:
if (!empty($post_link)) {
return $post_link;
}
if (!isset($entry)) {
$entry = null;
}
return $field->get_field_input($form, $value, $entry);
break;
}
}
示例8: modify_edit_field_input
/**
*
* Fill-in the saved values into the form inputs
*
* @param string $field_content Always empty.
* @param GF_Field $field
* @param string|array $value If array, it's a field with multiple inputs. If string, single input.
* @param int $lead_id Lead ID. Always 0 for the `gform_field_input` filter.
* @param int $form_id Form ID
*
* @return mixed
*/
function modify_edit_field_input($field_content = '', $field, $value, $lead_id = 0, $form_id)
{
// If the form has been submitted, then we don't need to pre-fill the values,
// Except for fileupload type - run always!!
if ($this->is_edit_entry_submission() && 'fileupload' !== $field->type || GFCommon::is_product_field($field->type)) {
return $field_content;
}
// Turn on Admin-style display for file upload fields only
if ('fileupload' === $field->type) {
$_GET['page'] = 'gf_entries';
}
// SET SOME FIELD DEFAULTS TO PREVENT ISSUES
$field->adminOnly = false;
/** @see GFFormDisplay::get_counter_init_script() need to prevent adminOnly */
// add categories as choices for Post Category field
if ('post_category' === $field->type) {
$field = GFCommon::add_categories_as_choices($field, $value);
}
// We're dealing with multiple inputs (e.g. checkbox)
if (isset($field->inputs) && is_array($field->inputs)) {
$field_value = array();
// only accept pre-populated values if the field doesn't have any choice selected.
$allow_pre_populated = true;
foreach ((array) $field->inputs as $input) {
$input_id = strval($input['id']);
if (!empty($this->entry[$input_id])) {
$allow_pre_populated = false;
$field_value[$input_id] = 'post_category' === $field->type ? GFCommon::format_post_category($this->entry[$input_id], true) : $this->entry[$input_id];
}
}
if ($allow_pre_populated) {
$field_value = $field->get_value_submission(array(), false);
}
} else {
$id = intval($field->id);
// get pre-populated value if exists
$pre_value = $field->allowsPrepopulate ? GFFormsModel::get_parameter_value($field->inputName, array(), $field) : '';
// saved field entry value (if empty, fallback to the pre-populated value, if exists)
$field_value = !empty($this->entry[$id]) ? $this->entry[$id] : $pre_value;
// in case field is post_category but inputType is select, multi-select or radio, convert value into array of category IDs.
if ('post_category' === $field->type && !empty($field_value)) {
$categories = array();
foreach (explode(',', $field_value) as $cat_string) {
$categories[] = GFCommon::format_post_category($cat_string, true);
}
$field_value = 'multiselect' === $field->get_input_type() ? $categories : implode('', $categories);
}
}
// if value is empty get the default value if defined
$field_value = $field->get_value_default_if_empty($field_value);
// Prevent any PHP warnings, like undefined index
ob_start();
$return = $field->get_field_input($this->form, $field_value, $this->entry);
// If there was output, it's an error
$warnings = ob_get_clean();
if (!empty($warnings)) {
do_action('gravityview_log_error', __METHOD__ . $warnings);
}
/**
* Unset hack $_GET['page'] = 'gf_entries'
* We need the fileupload html field to render with the proper id
* ( <li id="field_80_16" ... > )
*/
unset($_GET['page']);
return $return;
}
示例9: modify_edit_field_input
/**
*
* Fill-in the saved values into the form inputs
*
* @param string $field_content Always empty. Returning not-empty overrides the input.
* @param GF_Field $field
* @param string|array $value If array, it's a field with multiple inputs. If string, single input.
* @param int $lead_id Lead ID. Always 0 for the `gform_field_input` filter.
* @param int $form_id Form ID
*
* @return mixed
*/
function modify_edit_field_input($field_content = '', $field, $value, $lead_id = 0, $form_id)
{
$gv_field = GravityView_Fields::get_associated_field($field);
// If the form has been submitted, then we don't need to pre-fill the values,
// Except for fileupload type and when a field input is overridden- run always!!
if ($this->is_edit_entry_submission() && !in_array($field->type, array('fileupload', 'post_image')) && false === ($gv_field && is_callable(array($gv_field, 'get_field_input'))) || !empty($field_content) || in_array($field->type, array('honeypot')) || GFCommon::is_product_field($field->type)) {
return $field_content;
}
// Turn on Admin-style display for file upload fields only
if ('fileupload' === $field->type) {
$_GET['page'] = 'gf_entries';
}
// SET SOME FIELD DEFAULTS TO PREVENT ISSUES
$field->adminOnly = false;
/** @see GFFormDisplay::get_counter_init_script() need to prevent adminOnly */
// add categories as choices for Post Category field
if ('post_category' === $field->type) {
$field = GFCommon::add_categories_as_choices($field, $value);
}
$field_value = $this->get_field_value($field);
/**
* @filter `gravityview/edit_entry/field_value` Change the value of an Edit Entry field, if needed
* @since 1.11
* @param mixed $field_value field value used to populate the input
* @param object $field Gravity Forms field object ( Class GF_Field )
*/
$field_value = apply_filters('gravityview/edit_entry/field_value', $field_value, $field);
/**
* @filter `gravityview/edit_entry/field_value_{field_type}` Change the value of an Edit Entry field for a specific field type
* @since 1.17
* @param mixed $field_value field value used to populate the input
* @param GF_Field $field Gravity Forms field object
*/
$field_value = apply_filters('gravityview/edit_entry/field_value_' . $field->type, $field_value, $field);
// Prevent any PHP warnings, like undefined index
ob_start();
if ($gv_field && is_callable(array($gv_field, 'get_field_input'))) {
/** @var GF_Field $gv_field */
$return = $gv_field->get_field_input($this->form, $field_value, $this->entry, $field);
} else {
$return = $field->get_field_input($this->form, $field_value, $this->entry);
}
// If there was output, it's an error
$warnings = ob_get_clean();
if (!empty($warnings)) {
do_action('gravityview_log_error', __METHOD__ . $warnings, $field_value);
}
/**
* Unset hack $_GET['page'] = 'gf_entries'
* We need the fileupload html field to render with the proper id
* ( <li id="field_80_16" ... > )
*/
unset($_GET['page']);
return $return;
}