<?xml version="1.0" encoding="UTF-8"?>
<!-- generator="bbPress/1.0.1" -->
<rss version="2.0"
	xmlns:content="http://purl.org/rss/1.0/modules/content/"
	xmlns:dc="http://purl.org/dc/elements/1.1/"
	xmlns:atom="http://www.w3.org/2005/Atom">
	<channel>
		<title>Gravity Support Forums Topic: Updating an existing lead</title>
		<link>https://legacy.forums.gravityhelp.com/topic/updating-an-existing-lead</link>
		<description>Gravity Support Forums Topic: Updating an existing lead</description>
		<language>en-US</language>
		<pubDate>Sun, 19 Apr 2026 18:36:22 +0000</pubDate>
		<generator>http://bbpress.org/?v=1.0.1</generator>
		<textInput>
			<title><![CDATA[Search]]></title>
			<description><![CDATA[Search all topics from these forums.]]></description>
			<name>q</name>
			<link>https://legacy.forums.gravityhelp.com/search.php</link>
		</textInput>
		<atom:link href="https://legacy.forums.gravityhelp.com/rss/topic/updating-an-existing-lead" rel="self" type="application/rss+xml" />

		<item>
			<title>Alex Cancado on "Updating an existing lead"</title>
			<link>https://legacy.forums.gravityhelp.com/topic/updating-an-existing-lead#post-376075</link>
			<pubDate>Thu, 25 Jul 2013 09:40:58 +0000</pubDate>
			<dc:creator>Alex Cancado</dc:creator>
			<guid isPermaLink="false">376075@https://legacy.forums.gravityhelp.com/</guid>
			<description>&#60;p&#62;Thanks for the code. The issue I have with this hook is that it kind of implies that you would be able to change the $lead array and your data would be saved. I think it would create some confusion.&#60;br /&#62;
How about something more specific to your scenario? Something like &#34;gform_lead_id_pre_save&#34;, which would filter just the lead id?&#60;/p&#62;
&#60;p&#62;As you know, we are in the process of closing this forum for support, so can you please reply by submitting the &#60;a href='http://www.gravityhelp.com/request-support/' rel=&#34;nofollow&#34;&#62;support form&#60;/a&#62;? Please add a link to this topic.&#60;/p&#62;
&#60;p&#62;Cheers,
&#60;/p&#62;</description>
		</item>
		<item>
			<title>Lowtone on "Updating an existing lead"</title>
			<link>https://legacy.forums.gravityhelp.com/topic/updating-an-existing-lead#post-370197</link>
			<pubDate>Tue, 09 Jul 2013 04:47:21 +0000</pubDate>
			<dc:creator>Lowtone</dc:creator>
			<guid isPermaLink="false">370197@https://legacy.forums.gravityhelp.com/</guid>
			<description>&#60;p&#62;Hi Alex,&#60;br /&#62;
I've added the code below. The original method comes from Gravity Forms v1.7.6. I made two other modifications in this version to prevent problems with the value returned by the filter.&#60;/p&#62;
&#60;p&#62;Instead of checking the $lead value to be NULL I've made it to check if the $lead value has an ID. To do so I had to cast $lead to an array (isset($lead[&#34;id&#34;]) would have worked on any type except for objects which would have caused a fatal error for using them as an array).&#60;/p&#62;
&#60;pre&#62;&#60;code&#62;public static function save_lead($form, &#38;amp;$lead){
    global $wpdb;

    GFCommon::log_debug(&#38;quot;Saving entry.&#38;quot;);

    if(IS_ADMIN &#38;amp;&#38;amp; !GFCommon::current_user_can_any(&#38;quot;gravityforms_edit_entries&#38;quot;))
        die(__(&#38;quot;You don&#38;#39;t have adequate permission to edit entries.&#38;quot;, &#38;quot;gravityforms&#38;quot;));

    $lead = apply_filters(&#38;quot;gform_pre_save_lead&#38;quot;, $lead);

    $lead_detail_table = self::get_lead_details_table_name();

    $lead = (array) $lead;

    //Inserting lead if null
    if(!isset($lead[&#38;quot;id&#38;quot;])) {
        global $current_user;
        $user_id = $current_user &#38;amp;&#38;amp; $current_user-&#38;gt;ID ? $current_user-&#38;gt;ID : &#38;#39;NULL&#38;#39;;

        $lead_table = RGFormsModel::get_lead_table_name();
        $user_agent = strlen($_SERVER[&#38;quot;HTTP_USER_AGENT&#38;quot;]) &#38;gt; 250 ? substr($_SERVER[&#38;quot;HTTP_USER_AGENT&#38;quot;], 0, 250) : $_SERVER[&#38;quot;HTTP_USER_AGENT&#38;quot;];
        $currency = GFCommon::get_currency();
        $wpdb-&#38;gt;query($wpdb-&#38;gt;prepare(&#38;quot;INSERT INTO $lead_table(form_id, ip, source_url, date_created, user_agent, currency, created_by) VALUES(%d, %s, %s, utc_timestamp(), %s, %s, {$user_id})&#38;quot;, $form[&#38;quot;id&#38;quot;], self::get_ip(), self::get_current_page_url(), $user_agent, $currency));

        //reading newly created lead id
        $lead_id = $wpdb-&#38;gt;insert_id;
        $lead = array(&#38;quot;id&#38;quot; =&#38;gt; $lead_id);

        GFCommon::log_debug(&#38;quot;Entry record created in the database. ID: {$lead_id}&#38;quot;);
    }

    $current_fields = $wpdb-&#38;gt;get_results($wpdb-&#38;gt;prepare(&#38;quot;SELECT id, field_number FROM $lead_detail_table WHERE lead_id=%d&#38;quot;, $lead[&#38;quot;id&#38;quot;]));
    $original_post_id = rgget(&#38;quot;post_id&#38;quot;, $lead);

    $total_field = null;
    $calculation_fields = array();
    $recalculate_total = false;

    GFCommon::log_debug(&#38;quot;Saving entry fields.&#38;quot;);

    foreach($form[&#38;quot;fields&#38;quot;] as $field){

        //Ignore fields that are marked as display only
        if(rgget(&#38;quot;displayOnly&#38;quot;, $field) &#38;amp;&#38;amp; $field[&#38;quot;type&#38;quot;] != &#38;quot;password&#38;quot;){
            continue;
        }

        //ignore pricing fields in the entry detail
        if(RG_CURRENT_VIEW == &#38;quot;entry&#38;quot; &#38;amp;&#38;amp; GFCommon::is_pricing_field($field[&#38;quot;type&#38;quot;])){
            continue;
        }

        //process total field after all fields have been saved
        if($field[&#38;quot;type&#38;quot;] == &#38;quot;total&#38;quot;){
            $total_field = $field;
            continue;
        }

        //only save fields that are not hidden (except on entry screen)
        if(RG_CURRENT_VIEW == &#38;quot;entry&#38;quot; &#124;&#124; !RGFormsModel::is_field_hidden($form, $field, array()) ){

            // process calculation fields after all fields have been saved (moved after the is hidden check)
            if( GFCommon::has_field_calculation($field) ) {
                $calculation_fields[] = $field;
                continue;
            }

            GFCommon::log_debug(&#38;quot;Saving field {$field[&#38;quot;label&#38;quot;]}&#38;quot;);

            if($field[&#38;#39;type&#38;#39;] == &#38;#39;post_category&#38;#39;)
                $field = GFCommon::add_categories_as_choices($field, &#38;#39;&#38;#39;);

            if(isset($field[&#38;quot;inputs&#38;quot;]) &#38;amp;&#38;amp; is_array($field[&#38;quot;inputs&#38;quot;])){

                foreach($field[&#38;quot;inputs&#38;quot;] as $input)
                    self::save_input($form, $field, $lead, $current_fields, $input[&#38;quot;id&#38;quot;]);
            }
            else{
                self::save_input($form, $field, $lead, $current_fields, $field[&#38;quot;id&#38;quot;]);
            }
        }
    }

    if(!empty($calculation_fields)) {
        foreach($calculation_fields as $calculation_field) {

            GFCommon::log_debug(&#38;quot;Saving calculated field {$calculation_field[&#38;quot;label&#38;quot;]}&#38;quot;);

            if(isset($calculation_field[&#38;quot;inputs&#38;quot;]) &#38;amp;&#38;amp; is_array($calculation_field[&#38;quot;inputs&#38;quot;])){
                foreach($calculation_field[&#38;quot;inputs&#38;quot;] as $input) {
                    self::save_input($form, $calculation_field, $lead, $current_fields, $input[&#38;quot;id&#38;quot;]);
                    self::refresh_lead_field_value($lead[&#38;quot;id&#38;quot;], $input[&#38;quot;id&#38;quot;]);
                }
            }
            else{
                self::save_input($form, $calculation_field, $lead, $current_fields, $calculation_field[&#38;quot;id&#38;quot;]);
                self::refresh_lead_field_value($lead[&#38;quot;id&#38;quot;], $calculation_field[&#38;quot;id&#38;quot;]);
            }

        }
        self::refresh_product_cache($form, $lead = RGFormsModel::get_lead($lead[&#38;#39;id&#38;#39;]));
    }

    //saving total field as the last field of the form.
    if($total_field) {
        GFCommon::log_debug(&#38;quot;Saving total field.&#38;quot;);
        self::save_input($form, $total_field, $lead, $current_fields, $total_field[&#38;quot;id&#38;quot;]);
    }

}&#60;/code&#62;&#60;/pre&#62;</description>
		</item>
		<item>
			<title>Alex Cancado on "Updating an existing lead"</title>
			<link>https://legacy.forums.gravityhelp.com/topic/updating-an-existing-lead#post-368748</link>
			<pubDate>Mon, 08 Jul 2013 15:38:58 +0000</pubDate>
			<dc:creator>Alex Cancado</dc:creator>
			<guid isPermaLink="false">368748@https://legacy.forums.gravityhelp.com/</guid>
			<description>&#60;p&#62;Thanks for the suggestion. Would you mind sending me the entire save_lead() function so that I can look into adding this hook for you?
&#60;/p&#62;</description>
		</item>
		<item>
			<title>David Peralty on "Updating an existing lead"</title>
			<link>https://legacy.forums.gravityhelp.com/topic/updating-an-existing-lead#post-368156</link>
			<pubDate>Mon, 08 Jul 2013 10:37:45 +0000</pubDate>
			<dc:creator>David Peralty</dc:creator>
			<guid isPermaLink="false">368156@https://legacy.forums.gravityhelp.com/</guid>
			<description>&#60;p&#62;I have asked our developers to take a look at this and give any suggestions or opinions they may have. You are right though that updating core files is not the way to go.
&#60;/p&#62;</description>
		</item>
		<item>
			<title>Lowtone on "Updating an existing lead"</title>
			<link>https://legacy.forums.gravityhelp.com/topic/updating-an-existing-lead#post-367962</link>
			<pubDate>Mon, 08 Jul 2013 08:41:19 +0000</pubDate>
			<dc:creator>Lowtone</dc:creator>
			<guid isPermaLink="false">367962@https://legacy.forums.gravityhelp.com/</guid>
			<description>&#60;p&#62;Hello,&#60;br /&#62;
I'm looking for a way to update an existing lead instead of creating a new one on each submission.&#60;/p&#62;
&#60;p&#62;Using existing action hooks I figured this would be possible using the &#34;gform_after_submission&#34; action since this is the first hook with access to the lead used for the submission. This would however require a new lead to be created (by GFFormDisplay::handle_submission()) and then using the hook to either remove the earlier lead and update the new one with the ID from the earlier lead or update the values for the earlier lead with the new ones and remove the newly created lead. Besides being a bit complicated I could imagine that the lead ID jugling might cause other problems.&#60;/p&#62;
&#60;p&#62;Another solution would require the ability to access the lead data before a new one is created. I couldn't find such a hook so I've tried it by creating my own filter in GFFormsModel::save_lead() by adding this line after line 996:&#60;/p&#62;
&#60;pre&#62;&#60;code&#62;$lead = apply_filters(&#38;quot;gform_pre_save_lead&#38;quot;, $lead);&#60;/code&#62;&#60;/pre&#62;
&#60;p&#62;Using this filter to inject the lead ID for an existing lead into the lead data worked perfectly.&#60;/p&#62;
&#60;p&#62;Since I'm not a supporter of making modifications to existing plugins I am still wondering if I missed something and that there might be a better solution to the problem.&#60;/p&#62;
&#60;p&#62;Any suggestions?
&#60;/p&#62;</description>
		</item>

	</channel>
</rss>
