Home > Back-end >  Parsing entries of Gravity Forms lists in WordPress
Parsing entries of Gravity Forms lists in WordPress

Time:08-25

I am having trouble with parsing the entries of a Gravity Forms list in WordPress. ​ In my app, I use Gravity Forms lists, in order to allow the user to enter tables of the form: ​

"Fruit"  "Color"
 apple    green
  pear   yellow

​ ​ I see that my data are stored in $entry[5], which is a string variable that needs to be parsed (ie. $list_entries below). ​

function after_submission($entry, $form){
    $list_entries = $entry[5];
}

​ The issue is that I am not familiar with the format of the content of $list_entries, which is the following: a:2:{i:0;a:2:{s:2:"Fruit";s:16:"apple";s:2:"Color";s:10:"green";}i:1;a:2:{s:2:"Fruit";s:12:"pear";s:2:"Color";s:18:"yellow";}} ​ or, in a more readable form: ​

a:2:{
    i:0;a:2:{
        s:2:"Fruit";s:16:"apple";
        s:2:"Color";s:10:"green";
    }
    i:1;a:2:{
        s:2:"Fruit";s:12:"pear";
        s:2:"Color";s:18:"yellow";
    }
}

​ Is anyone familiar with this format?

CodePudding user response:

As AnotherAccount mentioned, this is serialized content.

Here's an example of how to get data from this type of field:

$list=unserialize( rgar( $entry, '5' ) );// unserialize the list field
$count=count($list);//count the rows
$fruits=array();//create an empty array to hold the fruits
$colors=array();//create an empty array to hold the colors
for($i=0;$i<$count;$i  ){//loop throw each list row
    $fruits[$i]= $list[$i]['Fruit'];//store each fruit value into the array
    $colors[$i]= $list[$i]['Color'];//store each color value into the array
}
print_r($fruits);
print_r($colors);
  • Related