Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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 );  
}

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.

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";}}

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.

like image 698
Org112 Avatar asked Jul 05 '26 12:07

Org112


1 Answers

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.

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

like image 100
leclaeli Avatar answered Jul 07 '26 12:07

leclaeli



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!