Ask your WordPress questions! Pay money and get answers fast! Comodo Trusted Site Seal
Official PayPal Seal

Display gravity form (plug-in) as table dynamically WordPress

  • SOLVED

I'm using buddypress. I have a form on each user profile. I would like to display the forms data based on a variable. My gravity form capture's the url where the form is submitted using {embed url}.

So if i submitted a form on www.example.com/user1 all the forms data that was submitted on that url will be shown on www.example.com/user1.

The code below shows the data, but i cant get it to change dynamically based on the user



$form_id = 18;
$entry_id = 190;

$form_meta = RGFormsModel::get_form_meta($form_id);
$entry = RGFormsModel::get_lead($entry_id);

echo "<hr/>Form Title: " . $form_meta["title"] . "<br/>";

//displaying all submitted fields
foreach($form_meta["fields"] as $field){

if(is_array($field["inputs"])){

//handling multi-input fields such as name and address
foreach($field["inputs"] as $input){
$value = $entry[strval($input["id"])];
$label = RGFormsModel::get_label($field, $input["id"]);
echo $label . ": " . $value . "<br/>";
}
}
else{
//handling single-input fields such as text and paragraph (textarea)
$value = $entry[$field["id"]];
echo $field["label"] . ": " . $value . "<br/>";
}
}
echo "<hr/>";





Answers (1)

2011-06-19

Daryl Lozupone answers:

oulab--

You are setting the entry_id on the second line:

$entry_id = 190;

Instead, search for the proper entry.

For example: (assuming your form field name for the embed_url is 'embed_url' :



$form_id = 1;

$form_meta = RGFormsModel::get_form_meta($form_id);

$current_url = "http://" . $_SERVER['SERVER_NAME'] . $_SERVER['REQUEST_URI'];

$entries = RGFormsModel::get_leads($form_id, 'embed_url', 'DESC', $current_url);

if( is_array( $entries ) ) {
foreach( $entries as $single_entry ) {
$entry = RGFormsModel::get_lead($single_entry['id'] );

echo "<hr/>Form Title: " . $form_meta["title"] . "<br/>";



//displaying all submitted fields

foreach($form_meta["fields"] as $field){



if(is_array($field["inputs"])){



//handling multi-input fields such as name and address

foreach($field["inputs"] as $input){

$value = $entry[strval($input["id"])];

$label = RGFormsModel::get_label($field, $input["id"]);

echo $label . ": " . $value . "<br/>";

}

}

else{

//handling single-input fields such as text and paragraph (textarea)

$value = $entry[$field["id"]];

echo $field["label"] . ": " . $value . "<br/>";

}

}

echo "<hr/>";
}
}










oulab comments:

Hi Daryl,

Almost there, only problem is its only displaying 1 return, not all of the returns.

So user1 has had 10 forms completed but only on is showing

Thanks,

Brian




Daryl Lozupone comments:

Brian--

I have edited my answer to include a foreach loop for the entries array. That should take care of it.

This update assumes that the user submitted the same form (form_id) multiple times, and that you wish to display all of their submissions of this one form.


I hope that helps.

--Daryl Lozupone


oulab comments:

Thanks Daryl. Thats done the trick.

much appreciated

Brian