PLEASE NOTE: These forums are no longer utilized and are provided as an archive for informational purposes only. All support issues will be handled via email using our support ticket system. For more detailed information on this change, please see this blog post.

Update Lead Meta

  1. Hi
    I am looking at ways of updating saved leads after the initial lead has been saved. I have been digging around forms_model.php and came up with the following code:

    @include_once(WP_PLUGIN_DIR . "/gravityforms/gravityforms.php");
    @include_once(WP_PLUGIN_DIR . "/gravityforms/forms_model.php");
    $rg = new RGFormsModel(); 
    
    $lead_id = 12;
    
    $rg->update_lead_property($lead_id, 'custom', 200);

    If I am trying to adjust a field within the rg_lead table (starred, ip, etc) then it would appear to work. However I cannot get it to update any value in the rg_lead_detail table - the custom field data for my form.

    Is there a function or class available for interacting with the rg_lead_detail table. Something like:

    $rg->update_lead_property_meta($lead_id, 'custom', 200);

    Thanks

    Posted 13 years ago on Friday April 8, 2011 | Permalink
  2. Unfortunately, there isn't a function to update the lead detail table. The code used to update lead details is inside the RGFormsModel::save_input() method, but that method relies on the $_POST variable to read the field values, so it won't work for you. You will have to write your own SQL queries for that one. That table is pretty straight forward, just remember that the field_number column relates to the field ID. Also, you will note that the value column can only take 200 characters. If your value is larger than 200, you will need to also add a record to the wp_rg_lead_detail_long table.

    Posted 13 years ago on Friday April 8, 2011 | Permalink
  3. Hi Alex
    Thanks for getting back. I have written the following code and it works well. My form redirects the user to a URL with a unique GET variable. This unique ID is used to retrieve the form information and then update the download counter. Only a certain number of downloads are permitted. Hopefully the code will be of use to others:

    global $wpdb;
    
    // get gravity forms
    $rg = new RGFormsModel(); 
    
    // search for this UID on form 2
    $download = $rg->get_leads(2, 0, 'DESC', $_GET['uid'], 0, 1000);	
    
    // invalid UID
    if (!$download) { wp_die(__('Invalid download link.','oo').' <a href="'.get_bloginfo('url').'">'.__('Get me out of here »','oo').'</a>'); }
    
    // counter
    $counter = $download[0][5];
    if ($counter >= 2) { wp_die(__('File download limit exceeded.','oo').' <a href="'.get_bloginfo('url').'">'.__('Get me out of here »','oo').'</a>'); }
    
    // update the counter (form 2, field 5)
    $lead_detail_table = $rg->get_lead_details_table_name();
    $count = $counter + 1;
    $save = $wpdb->update($lead_detail_table, array("value" => $count), array("lead_id" => $download[0]["id"], "form_id" => 2, "field_number" => 5));

    It would be useful for a having a few template functions for working with form data. Simple update, edit, retrieve, delete functions. While this goes beyond just data collection and the core of Gravity Forms it would massively increase the flexibility of the plugin.

    Thank again

    Scott

    Posted 13 years ago on Monday April 11, 2011 | Permalink
  4. I vote for this as well

    It would be useful for a having a few template functions for working with form data. Simple update, edit, retrieve, delete functions. While this goes beyond just data collection and the core of Gravity Forms it would massively increase the flexibility of the plugin.

    Posted 12 years ago on Friday April 29, 2011 | Permalink
  5. +1 for a GFFormsModel::save_input() like function for updating lead details without form input.

    Posted 10 years ago on Tuesday May 21, 2013 | Permalink
  6. David Peralty

    I'm going to move this to feature requests so people can continue to leave their support.

    Posted 10 years ago on Tuesday May 21, 2013 | Permalink