<?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: Javascript code in confirmation message is executed twice for Ajax form</title>
		<link>https://legacy.forums.gravityhelp.com/topic/javascript-code-in-confirmation-message-is-executed-twice-for-ajax-form</link>
		<description>Gravity Support Forums Topic: Javascript code in confirmation message is executed twice for Ajax form</description>
		<language>en-US</language>
		<pubDate>Wed, 22 Apr 2026 01:54:18 +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/javascript-code-in-confirmation-message-is-executed-twice-for-ajax-form" rel="self" type="application/rss+xml" />

		<item>
			<title>Rob Harrell on "Javascript code in confirmation message is executed twice for Ajax form"</title>
			<link>https://legacy.forums.gravityhelp.com/topic/javascript-code-in-confirmation-message-is-executed-twice-for-ajax-form#post-332096</link>
			<pubDate>Wed, 19 Jun 2013 10:30:02 +0000</pubDate>
			<dc:creator>Rob Harrell</dc:creator>
			<guid isPermaLink="false">332096@https://legacy.forums.gravityhelp.com/</guid>
			<description>&#60;p&#62;Eugen,&#60;/p&#62;
&#60;p&#62;You would need to use the gform_confirmation_loaded hook instead:&#60;br /&#62;
&#60;a href=&#34;http://www.gravityhelp.com/documentation/page/Gform_confirmation_loaded&#34; rel=&#34;nofollow&#34;&#62;http://www.gravityhelp.com/documentation/page/Gform_confirmation_loaded&#60;/a&#62;
&#60;/p&#62;</description>
		</item>
		<item>
			<title>Anonymous on "Javascript code in confirmation message is executed twice for Ajax form"</title>
			<link>https://legacy.forums.gravityhelp.com/topic/javascript-code-in-confirmation-message-is-executed-twice-for-ajax-form#post-332074</link>
			<pubDate>Wed, 19 Jun 2013 10:16:15 +0000</pubDate>
			<dc:creator>Anonymous</dc:creator>
			<guid isPermaLink="false">332074@https://legacy.forums.gravityhelp.com/</guid>
			<description>&#60;p&#62;Hi guys,&#60;/p&#62;
&#60;p&#62;Any update regarding these issues? Please let me know if there are some parts in the above  post that are not clearly explained.&#60;/p&#62;
&#60;p&#62;Thank you in advance!&#60;br /&#62;
Eugen
&#60;/p&#62;</description>
		</item>
		<item>
			<title>Anonymous on "Javascript code in confirmation message is executed twice for Ajax form"</title>
			<link>https://legacy.forums.gravityhelp.com/topic/javascript-code-in-confirmation-message-is-executed-twice-for-ajax-form#post-321392</link>
			<pubDate>Thu, 13 Jun 2013 18:31:09 +0000</pubDate>
			<dc:creator>Anonymous</dc:creator>
			<guid isPermaLink="false">321392@https://legacy.forums.gravityhelp.com/</guid>
			<description>&#60;p&#62;Hi,&#60;/p&#62;
&#60;p&#62;I use the &#34;gform_confirmation&#34; action to post submitted data to a third-party application. If the submission is successful, I need to include Javascript code in the confirmation message to track the conversion. &#60;/p&#62;
&#60;p&#62;For testing I have used just an &#60;code&#62;alert(&#38;quot;Conversion happened&#38;quot;)&#60;/code&#62; box and noticed that it is shown twice for Ajax-enabled forms. I have not yet tested with the actual conversion code, but my guess is that 2 conversions will occur instead of one because of this behaviour.&#60;/p&#62;
&#60;p&#62;After several hours of debugging I have found out that this happens because the JS code is executed once inside the hidden &#38;lt;iframe&#38;gt; used as the target for Ajax-enabled forms and once when the confirmation message is added to the page (in GFFormDisplay::get_form() method - line 607 from &#34;form_display.php&#34;, GF 1.7.5):&#60;/p&#62;
&#60;pre&#62;&#60;code&#62;&#38;quot;jQuery(&#38;#39;#gform_wrapper_{$form_id}&#38;#39;).replaceWith(&#38;#39;&#38;lt;&#38;#39; + &#38;#39;div id=\&#38;#39;gforms_confirmation_message\&#38;#39; class=\&#38;#39;gform_confirmation_message_{$form_id}\&#38;#39;&#38;#39; + &#38;#39;&#38;gt;&#38;#39; + confirmation_content + &#38;#39;&#38;lt;&#38;#39; + &#38;#39;/div&#38;#39; + &#38;#39;&#38;gt;&#38;#39;);&#38;quot; .&#60;/code&#62;&#60;/pre&#62;
&#60;p&#62;The solution I came up with was to remove &#38;lt;script&#38;gt; / &#38;lt;noscript&#38;gt; tags from the confirmation message before it is inserted in the page - this way scripts are executed only once inside the hidden &#38;lt;iframe&#38;gt;. For backwards compatibility, I made this configurable using &#34;gform_confirmation_scripts_once&#34; filter. Please see the unified diff file here: &#60;/p&#62;
&#60;p&#62;&#60;a href=&#34;http://pastie.org/8040491&#34; rel=&#34;nofollow&#34;&#62;http://pastie.org/8040491&#60;/a&#62;&#60;/p&#62;
&#60;p&#62;Another possible issue is on line 604 from &#34;form_display.php&#34;:&#60;br /&#62;
&#60;pre&#62;&#60;code&#62;&#38;quot;confirmation_content = contents;&#38;quot;.&#60;/code&#62;&#60;/pre&#62;
&#60;p&#62;where &#34;contents&#34; variable is set on line 585:&#60;br /&#62;
&#60;pre&#62;&#60;code&#62;&#38;quot;var contents = jQuery(this).contents().find(&#38;#39;*&#38;#39;).html();&#38;quot; .&#60;/code&#62;&#60;/pre&#62;
&#60;p&#62;This will insert the entire content of the hidden &#38;lt;iframe&#38;gt;, including the:&#60;br /&#62;
&#60;pre&#62;&#60;code&#62;&#38;lt;head&#38;gt;&#38;lt;meta charset=&#38;#39;UTF-8&#38;#39; /&#38;gt;&#38;lt;/head&#38;gt;&#60;/code&#62;&#60;/pre&#62;
&#60;p&#62;element inside the &#34;#gforms_confirmation_message&#34; &#38;lt;div&#38;gt;. In my opinion, only the &#38;lt;iframe&#38;gt; body content should be inserted in the page, so line 604 should be:&#60;br /&#62;
&#60;pre&#62;&#60;code&#62;&#38;quot;confirmation_content = jQuery(this).contents().find(&#38;#39;.GF_AJAX_POSTBACK&#38;#39;).html();&#38;quot;.&#60;/code&#62;&#60;/pre&#62;
&#60;p&#62;The diff file above includes all these changes. It would be nice if you could include them in the next GF version, if they seem correct to you. &#60;/p&#62;
&#60;p&#62;Kind regards,&#60;br /&#62;
Eugen
&#60;/p&#62;</description>
		</item>

	</channel>
</rss>
