WordPress重力形式获取列表值 [英] Wordpress Gravity Forms get List values
问题描述
有人可以指导我如何从包含列表字段的已提交表单中提取值吗?
Can somebody point me in the direction on how to extract values from submitted forms containing list fields?
我正在尝试使用以下方法创建前端发布表单重力形式,然后将提交的值分配给使用高级自定义字段创建的自定义字段。
I'm trying to create a front-end posting form using Gravity Forms, and then having the submitted values be assigned to custom fields made with Advanced Custom Fields.
对于普通字段,您可以使用以下方法执行此操作:
For normal fields, you can do this with the following:
add_action("gform_after_submission_1", "acf_submission", 10, 2);
function acf_submission($entry, $form)
{
$post_id = $entry["post_id"];
update_field('field_###', $entry['#'], $post_id );
update_field('field_###', $entry['#'], $post_id );
update_field('field_###', $entry['#'], $post_id );
}
其中field _ ###是ACF自定义字段键,entry ['# ']是重力表单字段ID,$ post_id是要更新/存储值的帖子的ID。
Where field_### is the ACF custom field key, entry['#'] is the Gravity Forms field ID, and $post_id is the id of the post you want to update/store values to.
使用条目['#']对于普通字段(文本,段落等)非常有用,但是列表(重复)字段的存储方式有所不同。在数据库中,该值看起来像这样(对于具有3个字段(列)的列表字段,对于单击添加按钮以添加列表字段的其他实例的人:
Using entry['#'] works great with normal fields (text, paragraph, etc.), but list (repeater) fields are stored a bit differently. In the DB, the value looks like this (for a list field that has 3 fields (columns), and for somebody who clicked the add button to add an additional instance of the list field:
a:2:{i:0;a:3:{s:4:"Column 1 Name";s:7:"value input";s:6:"Column 2 Name";s:34:"value input";s:11:"Column 3 Name";s:24:"value input";}i:1;a:3:{s:4:"Column 1 Name";s:11:"value input";s:6:"Column 2 Name";s:19:"value input";s:11:"Column 3 Name";s:22:"value input";}}
我不知道如何提取这些值并将其分配给ACF字段我尝试了entry ['#。#'],就像您对地址等字段所做的那样,但这没有用。
I can't figure out how to extract those values and assign them to ACF fields. I tried entry['#.#'] as you would do for fields like address, but that didn't work.
推荐答案
这是一个序列化数组,因此您可以使用php函数unserialize提取值。
This is a serialized array so you can use the php function unserialize to extract the values.
$array_values = unserialize($entry['#']);
print_r($array_values); //see what your values are.
现在您有了自己的值,就可以在新的$ array_values数组中访问它们。
从序列化数组中获取一个值在PHP中
Now that you have your values you can access them in your new $array_values array. Getting one value out of a serialized array in PHP
这篇关于WordPress重力形式获取列表值的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!