You guys are looking to do exactly what I just did. Here's the quick rundown.
Gravity Forms stores form entries as field number = field value. Each entry also includes the form number. There isn't an easy way to work with that unless you make a chart of your field numbers and what they represent. As in, field 5 = email address; field 6 = work phone number; etc. When you have that, you can simply query the Gravity Form table to display your info. on the front end using INNER JOINs. But that does get pretty tedious.
What I did was make a plugin that sets up some new tables -- members, member_meta, etc -- and then uses the post_submission hook to call up a function that adds members to those tables. Then I can easily work with them. So right now I have a table with the standard gravity forms entries and completely separate tables that have the same info. as the forms (initially, anyhow) which are what I then work with.
If you want to just do simple lists of info. from your forms, a great work around is to install the Shortcode Exec PHP plugin. That lets you create a short code from the backend and stick whatever code you want as the shortcode's action. So if you want to get a list of names and email addresses from a form, you can use the plugin to make a new short code. In the dashboard you just the text you want to use for the shortcode, like 'my-list' and below that you get a WYSIWYG box where you can enter the php code to display the list. As an example: If you have a form whose ID is 1 and two fields you want to display, a name field with ids 3.3 for first name and 3.6 for last name, and an email address field with id 5, then you could paste the following.
global $wpdb;
$results = $wpdb->get_results("SELECT f.id, f1.value as first_name, f2.value as last_name, f3.value as email FROM ".$wpdb->prefix."rg_lead as f INNER JOIN ".$wpdb->prefix."rg_lead_detail as f1 ON (f.id = f1.lead_id AND f1.field_number = '3.3') INNER JOIN ".$wpdb->prefix."rg_lead_detail as f2 ON (f.id = f2.lead_id AND f2.field_number = '3.6') INNER JOIN ".$wpdb->prefix."rg_lead_detail as f3 ON (f.id = f3.lead_id AND f3.field_number = '5') WHERE f.form_id = '1');
foreach ($results as $result){
echo "Name: ".$result['first_name']." ".$result['last_name']."";
echo "Email: ".$result['email']."------------";
}
Then you can use your new shortcode [my-list] in your pages and posts.
For each form field you want to display, just do another INNER JOIN. At the start of the sql statement you're listing all of the fields you want returned and using aliases so that you can easily access them. So if you had another field, age, you could add f4.value as age and then another INNER JOIN ".$wpdb->prefix."rg_lead_detail as f4 ON (f.id = f4.lead_id AND f4.field_number = '6') -- making sure to change the field_number to whatever corresponds to your age field.
Posted 14 years ago on Wednesday June 23, 2010 |
Permalink