Query Leads from Gravity Forms

Gravity Forms for WordPress is a full featured contact form plugin that features a drag and drop interface, advanced notification routing, lead capture, conditional logic fields, multi-page forms, pricing calculations and the ability to create posts from external forms.”

There are multiple options how to handle the confirmation page. Gravity form allows you to send query parameters to the page it is redirecting to.

You can send all form information in the clear, via query variables, but that looks really messy. Its better to use something like this .. lead_id={entry_id}  and query form information on the actual confirmation page.

GET THE LEAD

This will output the submitted form data as an array, with all fields linked by field id.

  1. $lead_id = intval( $_GET['lead_id'] );
  2. $lead = RGFormsModel::get_lead($lead_id);

TRANSLATE FIELD IDS TO FIELD LABELS

When you are reusing the field data for your own purposes, its easier to deal with field  names than with fields ids. So we get the form meta data

  1. $form = RGFormsModel::get_form_meta( $lead['form_id'] );
  2.  
  3. foreach( $form['fields'] as $field ) {
  4.  
  5.  $values[$field['id']] = array(
  6.         'id'    => $field['id'],
  7.         'label' => $field['label'],
  8.         'value' => $lead[ $field['id'] ],
  9.  );
  10. }

and extend the lead array.

  1. foreach($lead as $key => $val){
  2.  if(is_numeric($key)){
  3.   $lead_key = str_replace(" ", "_", strtolower($values[$key]['label']));
  4.   $lead[$lead_key] = $val;     
  5.  }
  6. }

Before you needed to know the actual field id to get its value. Now you can use the generated lead key to get that value.

BEFORE

  1. $field_key = 10;
  2. echo $lead[$field_key];

AFTER

  1. $field_key = "e-mail";
  2. echo $lead[$field_key];

Much easier to reuse and remember :)

Enjoy coding ….

Alex

I am a full-stack developer. I love programming,  design and know my way around server architecture as well.  I would never feel complete, with one of these missing. I have a broad range of interests, that’s why I constantly dive into new technologies and expand my knowledge where ever required. Technologies are evolving fast and I enjoy using the latest. Apart from that, I am a peace loving guy who tries to have people around him that think the same.  I truly believe in the principle: “If you help someone, someone will help you, when you need it."

Recent Posts

B&B / Hotel Booking Solutions for WordPress | 2024

BOOKING SOLUTIONS 202x This is my take on a subset of booking, appointment, PMS or… Read More

4 weeks ago

WordPress Cron + WP-CLI + Ntfy

THE GOAL Create a system cron for WordPress, that is accessible and can be easily… Read More

2 months ago

2024 is here and now :)

2024, what's cooking? Slowly getting into the 2024 spirit. 3 projects coming to a close… Read More

4 months ago

2023 ends and whats next !

Short look back at 2023 This has been a busy and interesting year. I am… Read More

4 months ago

cubicFUSION Grid Tweaker – Elementor Grid made easy.

Elementor Pro provides grid containers as an experimental feature. The options provided are limited, when… Read More

5 months ago

Archaeology Travel Booth – Travel Innovation Summit 2023

Archaeology Travel is an online travel guide for people who enjoy exploring the world’s pasts.… Read More

6 months ago