<?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: Programmatically create entry</title>
		<link>https://legacy.forums.gravityhelp.com/topic/programmatically-create-entry</link>
		<description>Gravity Support Forums Topic: Programmatically create entry</description>
		<language>en-US</language>
		<pubDate>Fri, 03 Apr 2026 23:20:40 +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/programmatically-create-entry" rel="self" type="application/rss+xml" />

		<item>
			<title>ixistudio on "Programmatically create entry"</title>
			<link>https://legacy.forums.gravityhelp.com/topic/programmatically-create-entry#post-287437</link>
			<pubDate>Wed, 29 May 2013 21:13:36 +0000</pubDate>
			<dc:creator>ixistudio</dc:creator>
			<guid isPermaLink="false">287437@https://legacy.forums.gravityhelp.com/</guid>
			<description>&#60;p&#62;I tried arrong s code and it works well, however if you want to use the native gravity forms functionality, I basically copied the save_lead function to the functions.php file, removed the admin only access to the function and changed its path (see below). To make it work you just pass the form object as $form and let it deal with $lead it self so it inserts the proper lead id). &#60;/p&#62;
&#60;p&#62;create_lead doesnt input the lead id so if you pass that as the $lead parameter it might not work. &#60;/p&#62;
&#60;p&#62;The function Im using:&#60;/p&#62;
&#60;pre&#62;&#60;code&#62;// Taken from the GF forms_model.php file, removed admin only access and replace self:: with RGFormsModel::
function local_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_detail_table = RGFormsModel::get_lead_details_table_name();

	//Inserting lead if null
	if($lead == null){
		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;], RGFormsModel::get_ip(), RGFormsModel::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)
					RGFormsModel::save_input($form, $field, $lead, $current_fields, $input[&#38;quot;id&#38;quot;]);
			}
			else{
				RGFormsModel::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) {
					RGFormsModel::save_input($form, $calculation_field, $lead, $current_fields, $input[&#38;quot;id&#38;quot;]);
					RGFormsModel::refresh_lead_field_value($lead[&#38;quot;id&#38;quot;], $input[&#38;quot;id&#38;quot;]);
				}
			}
			else{
				RGFormsModel::save_input($form, $calculation_field, $lead, $current_fields, $calculation_field[&#38;quot;id&#38;quot;]);
				RGFormsModel::refresh_lead_field_value($lead[&#38;quot;id&#38;quot;], $calculation_field[&#38;quot;id&#38;quot;]);
			}

		}
		RGFormsModel::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;);
		RGFormsModel::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>arrongibson on "Programmatically create entry"</title>
			<link>https://legacy.forums.gravityhelp.com/topic/programmatically-create-entry#post-286997</link>
			<pubDate>Wed, 29 May 2013 15:02:03 +0000</pubDate>
			<dc:creator>arrongibson</dc:creator>
			<guid isPermaLink="false">286997@https://legacy.forums.gravityhelp.com/</guid>
			<description>&#60;p&#62;I have been able to do this.  This is part of larger code so please ensure you run this at or after the 'init' action so that the 'GFFormsModel' class is available.&#60;/p&#62;
&#60;pre&#62;&#60;code&#62;public static function add_leads($form_id, $qty, $start = 1){
        global $wpdb;
        $table = $wpdb-&#38;gt;prefix.&#38;#39;rg_lead&#38;#39;;
        $tableDetail = $wpdb-&#38;gt;prefix.&#38;#39;rg_lead_detail&#38;#39;;
        $form = GFFormsModel::get_form_meta($form_id);
        $lead = GFFormsModel::create_lead($form);
        $itt = $start;
        for($j=0;$j&#38;lt;$qty;$j++){
            foreach ($form[&#38;#39;fields&#38;#39;] as $field) {
                if($field[&#38;#39;type&#38;#39;] == &#38;#39;email&#38;#39;){
                    $lead[$field[&#38;#39;id&#38;#39;]] = md5($itt).&#38;#39;@md5.gen&#38;#39;;
                } elseif($field[&#38;#39;type&#38;#39;] == &#38;#39;text&#38;#39;) {
                    $lead[$field[&#38;#39;id&#38;#39;]] = md5($itt);
                }
            }
            // var_dump($lead);
            unset($lead[&#38;#39;id&#38;#39;]);
            unset($lead[&#38;#39;post_id&#38;#39;]);
            $lead[&#38;#39;date_created&#38;#39;] = date(&#38;quot;Y-m-d H:i:s&#38;quot;);
            $leadMeta = array();
            $leadDetail = array();
            $leadDetails = array();
            foreach ($lead as $key =&#38;gt; $value) {
                if(gettype($key) == &#38;#39;integer&#38;#39;){
                    $leadDetail[&#38;#39;field_number&#38;#39;] = $key;
                    $leadDetail[&#38;#39;value&#38;#39;] = $value;
                    $leadDetail[&#38;#39;form_id&#38;#39;] = $form_id;
                    $leadDetails[] = $leadDetail;
                } else {
                    $leadMeta[$key] = $value;
                }
            }
            $wpdb-&#38;gt;insert($table, $leadMeta, array(&#38;#39;%s&#38;#39;,&#38;#39;%d&#38;#39;,&#38;#39;%s&#38;#39;,&#38;#39;%s&#38;#39;,&#38;#39;%s&#38;#39;,&#38;#39;%s&#38;#39;,&#38;#39;%d&#38;#39;,));
            $lead_id = $wpdb-&#38;gt;insert_id;
            for($i = 0; $i &#38;lt; count($leadDetails); $i++) {
                $leadDetails[$i][&#38;#39;lead_id&#38;#39;] = $lead_id;
            }
            // var_dump($leadDetails);
            foreach ($leadDetails as $leadDetail) {
                $wpdb-&#38;gt;insert($tableDetail, $leadDetail, array(&#38;#39;%d&#38;#39;,&#38;#39;%s&#38;#39;,&#38;#39;%d&#38;#39;,&#38;#39;%d&#38;#39;,));
            }
            $itt++;
        }
    }&#60;/code&#62;&#60;/pre&#62;
&#60;p&#62;what this does for me (when you call it) is just add garbage entries where the text fields are and MD5 hash of an increasing number and emails are that same hash @md5.com  this is really so i can test things with 1000s of entries.  you could obviously do something more eloquent.  message me if you need clarification.
&#60;/p&#62;</description>
		</item>
		<item>
			<title>Alex Cancado on "Programmatically create entry"</title>
			<link>https://legacy.forums.gravityhelp.com/topic/programmatically-create-entry#post-240125</link>
			<pubDate>Mon, 06 May 2013 15:54:31 +0000</pubDate>
			<dc:creator>Alex Cancado</dc:creator>
			<guid isPermaLink="false">240125@https://legacy.forums.gravityhelp.com/</guid>
			<description>&#60;p&#62;Unfortunately there is no easy way of manually creating an entry using a function. The RGFormsModel::create_lead() function creates an entry for use in PHP, but doesn't actually save it to the database. The RGFormsModel::save_lead() function saves the entry to the database, but gets its values from the POST variables.&#60;br /&#62;
The only suggestion I have for you is to study the save_lead() function and make a copy of it, changing the pieces you need.&#60;br /&#62;
Sorry I couldn't be of much help this time.
&#60;/p&#62;</description>
		</item>
		<item>
			<title>yougoteric on "Programmatically create entry"</title>
			<link>https://legacy.forums.gravityhelp.com/topic/programmatically-create-entry#post-239871</link>
			<pubDate>Mon, 06 May 2013 11:09:28 +0000</pubDate>
			<dc:creator>yougoteric</dc:creator>
			<guid isPermaLink="false">239871@https://legacy.forums.gravityhelp.com/</guid>
			<description>&#60;p&#62;Any progress here? Thanks.
&#60;/p&#62;</description>
		</item>
		<item>
			<title>David Peralty on "Programmatically create entry"</title>
			<link>https://legacy.forums.gravityhelp.com/topic/programmatically-create-entry#post-233648</link>
			<pubDate>Thu, 02 May 2013 10:41:23 +0000</pubDate>
			<dc:creator>David Peralty</dc:creator>
			<guid isPermaLink="false">233648@https://legacy.forums.gravityhelp.com/</guid>
			<description>&#60;p&#62;I've asked our developers to take a look, and maybe they can direct you on where to find the code you need.
&#60;/p&#62;</description>
		</item>
		<item>
			<title>yougoteric on "Programmatically create entry"</title>
			<link>https://legacy.forums.gravityhelp.com/topic/programmatically-create-entry#post-232956</link>
			<pubDate>Thu, 02 May 2013 01:10:32 +0000</pubDate>
			<dc:creator>yougoteric</dc:creator>
			<guid isPermaLink="false">232956@https://legacy.forums.gravityhelp.com/</guid>
			<description>&#60;p&#62;Is there a way to submit entries for a form using a function?&#60;br /&#62;
I have looked at   RGFormsModel::create_lead and RGFormsModel::save_lead, but am having a hard time finding the correct format of the data that needs to be passed as arguments.&#60;br /&#62;
Or perhaps there is a wpdb SQL call that would work for this?&#60;/p&#62;
&#60;p&#62;My use case is the collection of data in one form, with an &#34;opt in&#34; from another part of the site that would automatically create an entry.&#60;/p&#62;
&#60;p&#62;Any and all help here is appreciated.
&#60;/p&#62;</description>
		</item>

	</channel>
</rss>
