<?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: gform_enqueue_scripts injects script into iframe on validation error</title>
		<link>https://legacy.forums.gravityhelp.com/topic/gform_enqueue_scripts-injects-script-into-iframe-on-validation-error</link>
		<description>Gravity Support Forums Topic: gform_enqueue_scripts injects script into iframe on validation error</description>
		<language>en-US</language>
		<pubDate>Sat, 04 Apr 2026 05:11:10 +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/gform_enqueue_scripts-injects-script-into-iframe-on-validation-error" rel="self" type="application/rss+xml" />

		<item>
			<title>Richard Vav on "gform_enqueue_scripts injects script into iframe on validation error"</title>
			<link>https://legacy.forums.gravityhelp.com/topic/gform_enqueue_scripts-injects-script-into-iframe-on-validation-error#post-316671</link>
			<pubDate>Tue, 11 Jun 2013 05:01:24 +0000</pubDate>
			<dc:creator>Richard Vav</dc:creator>
			<guid isPermaLink="false">316671@https://legacy.forums.gravityhelp.com/</guid>
			<description>&#60;p&#62;Thanks Alex
&#60;/p&#62;</description>
		</item>
		<item>
			<title>Alex Cancado on "gform_enqueue_scripts injects script into iframe on validation error"</title>
			<link>https://legacy.forums.gravityhelp.com/topic/gform_enqueue_scripts-injects-script-into-iframe-on-validation-error#post-315708</link>
			<pubDate>Mon, 10 Jun 2013 16:00:15 +0000</pubDate>
			<dc:creator>Alex Cancado</dc:creator>
			<guid isPermaLink="false">315708@https://legacy.forums.gravityhelp.com/</guid>
			<description>&#60;p&#62;Enqueueing initialization scripts is a bit tricky, especially when dealing with AJAX forms. The recommended way of doing it is using the add_init_script() function. This function will make sure the script is printed at the right time and executed when needed. Some scripts need to be executed only once when the page is loaded, and some will need to be executed every time a conditional logic operation takes place, and this function has a parameter that controls that.&#60;br /&#62;
I have modified the sample code from richardvav above to use the add_init_script() function to give you an example.&#60;br /&#62;
&#60;a href=&#34;http://pastie.org/8031737&#34; rel=&#34;nofollow&#34;&#62;http://pastie.org/8031737&#60;/a&#62;&#60;/p&#62;
&#60;p&#62;I hope it is helpful and useful to all.
&#60;/p&#62;</description>
		</item>
		<item>
			<title>jacobdubail on "gform_enqueue_scripts injects script into iframe on validation error"</title>
			<link>https://legacy.forums.gravityhelp.com/topic/gform_enqueue_scripts-injects-script-into-iframe-on-validation-error#post-299196</link>
			<pubDate>Mon, 03 Jun 2013 12:00:49 +0000</pubDate>
			<dc:creator>jacobdubail</dc:creator>
			<guid isPermaLink="false">299196@https://legacy.forums.gravityhelp.com/</guid>
			<description>&#60;p&#62;Thanks richardvav!  &#60;/p&#62;
&#60;p&#62;I appreciate your help.  I'll give this new hook a try and report back.  &#60;/p&#62;
&#60;p&#62;Wondering if any of the core developers can chime in to let us know if this is intended behavior or not.&#60;/p&#62;
&#60;p&#62;Thanks again!&#60;br /&#62;
-Jacob
&#60;/p&#62;</description>
		</item>
		<item>
			<title>Richard Vav on "gform_enqueue_scripts injects script into iframe on validation error"</title>
			<link>https://legacy.forums.gravityhelp.com/topic/gform_enqueue_scripts-injects-script-into-iframe-on-validation-error#post-257452</link>
			<pubDate>Fri, 17 May 2013 07:11:19 +0000</pubDate>
			<dc:creator>Richard Vav</dc:creator>
			<guid isPermaLink="false">257452@https://legacy.forums.gravityhelp.com/</guid>
			<description>&#60;p&#62;Jacob, I tried your script on my localhost setup using a clean install and the twenty twelve theme and for some reason the script is being printed in both the head and the body so I am getting the &#34;jQuery is not defined&#34; error when the page first loads and the placeholders aren't appearing.&#60;/p&#62;
&#60;p&#62;Anyway if I swap from gform_enqueue_scripts to gform_pre_render and I bind the function to gform_post_render as shown below, the script is only printed in the body and the placeholders now appear and also work if the form is submitted and fails validation due to the field being empty.&#60;br /&#62;
&#60;pre&#62;&#60;code&#62;add_filter(&#38;#39;gform_pre_render&#38;#39;, &#38;#39;jtd_gform_enqueue_scripts&#38;#39;);
function jtd_gform_enqueue_scripts($form) {
?&#38;gt;
  &#38;lt;script&#38;gt;
    jQuery(document).bind(&#38;#39;gform_post_render&#38;#39;,function(){
    &#38;lt;?php
      /* Go through each one of the form fields */
      foreach($form[&#38;#39;fields&#38;#39;] as $i=&#38;gt;$field) {
        /* Check if the field has an assigned placeholder */
        if(isset($field[&#38;#39;placeholder&#38;#39;]) &#38;amp;&#38;amp; !empty($field[&#38;#39;placeholder&#38;#39;])){
          /* If a placeholder text exists, inject it as a new property to the field using jQuery */
          ?&#38;gt;
          jQuery(&#38;#39;#input_&#38;lt;?php echo $form[&#38;#39;id&#38;#39;]?&#38;gt;_&#38;lt;?php echo $field[&#38;#39;id&#38;#39;]?&#38;gt;&#38;#39;)
                 .attr(&#38;#39;placeholder&#38;#39;,&#38;quot;&#38;lt;?php echo $field[&#38;#39;placeholder&#38;#39;]?&#38;gt;&#38;quot;);
        &#38;lt;?php
        }
      }
    ?&#38;gt;
    });
  &#38;lt;/script&#38;gt;
&#38;lt;?php
     return $form;
}&#60;/code&#62;&#60;/pre&#62;
&#60;p&#62;However I still get the &#34;jQuery is not defined&#34; error when validation failed so it's not just gform_enqueue_scripts that results in the script being printed in the iframe and i'm at a loss as how to prevent it.
&#60;/p&#62;</description>
		</item>
		<item>
			<title>jacobdubail on "gform_enqueue_scripts injects script into iframe on validation error"</title>
			<link>https://legacy.forums.gravityhelp.com/topic/gform_enqueue_scripts-injects-script-into-iframe-on-validation-error#post-255683</link>
			<pubDate>Thu, 16 May 2013 12:14:04 +0000</pubDate>
			<dc:creator>jacobdubail</dc:creator>
			<guid isPermaLink="false">255683@https://legacy.forums.gravityhelp.com/</guid>
			<description>&#60;p&#62;Sure can.  Here you go:&#60;/p&#62;
&#60;pre&#62;&#60;code&#62;add_action(&#38;quot;gform_field_standard_settings&#38;quot;, &#38;quot;jtd_gform_placeholders&#38;quot;, 10, 2);

function jtd_gform_placeholders($position, $form_id){

  // Create settings on position 25 (right after Field Label)
  if ( $position == 25 ) {
  ?&#38;gt;

    &#38;lt;li class=&#38;quot;admin_label_setting field_setting&#38;quot; style=&#38;quot;display: list-item; &#38;quot;&#38;gt;
      &#38;lt;label for=&#38;quot;field_placeholder&#38;quot;&#38;gt;Placeholder Text
        &#38;lt;!-- Tooltip to help users understand what this field does --&#38;gt;
        &#38;lt;a href=&#38;quot;javascript:void(0);&#38;quot; class=&#38;quot;tooltip tooltip_form_field_placeholder&#38;quot; tooltip=&#38;quot;&#38;lt;h6&#38;gt;Placeholder&#38;lt;/h6&#38;gt;Enter the placeholder/default text for this field.&#38;quot;&#38;gt;(?)&#38;lt;/a&#38;gt;
      &#38;lt;/label&#38;gt;
      &#38;lt;input type=&#38;quot;text&#38;quot; id=&#38;quot;field_placeholder&#38;quot; class=&#38;quot;fieldwidth-3&#38;quot; size=&#38;quot;35&#38;quot; onkeyup=&#38;quot;SetFieldProperty(&#38;#39;placeholder&#38;#39;, this.value);&#38;quot;&#38;gt;
    &#38;lt;/li&#38;gt;
  &#38;lt;?php
  }
}

/* Now we execute some javascript technicalitites for the field to load correctly */

add_action(&#38;quot;gform_editor_js&#38;quot;, &#38;quot;jtd_gform_editor_js&#38;quot;);
function jtd_gform_editor_js(){
?&#38;gt;
  &#38;lt;script&#38;gt;
    //binding to the load field settings event to initialize the checkbox
    jQuery(document).bind(&#38;quot;gform_load_field_settings&#38;quot;, function(event, field, form){
      jQuery(&#38;quot;#field_placeholder&#38;quot;).val(field[&#38;quot;placeholder&#38;quot;]);
    });
  &#38;lt;/script&#38;gt;

&#38;lt;?php
}

/* We use jQuery to read the placeholder value and inject it to its field */

add_action(&#38;#39;gform_enqueue_scripts&#38;#39;,&#38;quot;jtd_gform_enqueue_scripts&#38;quot;, 10, 2);
function jtd_gform_enqueue_scripts( $form, $is_ajax ) {

  if ( $is_ajax ) :
?&#38;gt;
  &#38;lt;script&#38;gt;
    (function( $ ) {
    &#38;lt;?php
      /* Go through each one of the form fields */
      foreach($form[&#38;#39;fields&#38;#39;] as $i=&#38;gt;$field) {
        /* Check if the field has an assigned placeholder */
        if(isset($field[&#38;#39;placeholder&#38;#39;]) &#38;amp;&#38;amp; !empty($field[&#38;#39;placeholder&#38;#39;])){
          /* If a placeholder text exists, inject it as a new property to the field using jQuery */
          ?&#38;gt;
          jQuery(&#38;#39;#input_&#38;lt;?php echo $form[&#38;#39;id&#38;#39;]?&#38;gt;_&#38;lt;?php echo $field[&#38;#39;id&#38;#39;]?&#38;gt;&#38;#39;)
            .attr(&#38;#39;placeholder&#38;#39;,&#38;quot;&#38;lt;?php echo $field[&#38;#39;placeholder&#38;#39;]?&#38;gt;&#38;quot;);
        &#38;lt;?php
        }
      }
    ?&#38;gt;
    })(jQuery);
  &#38;lt;/script&#38;gt;
&#38;lt;?php
  endif; // $is_ajax
}&#60;/code&#62;&#60;/pre&#62;
&#60;p&#62;Hopefully that comes through correctly.&#60;/p&#62;
&#60;p&#62;Thanks again for your help!&#60;/p&#62;
&#60;p&#62;-Jacob
&#60;/p&#62;</description>
		</item>
		<item>
			<title>Richard Vav on "gform_enqueue_scripts injects script into iframe on validation error"</title>
			<link>https://legacy.forums.gravityhelp.com/topic/gform_enqueue_scripts-injects-script-into-iframe-on-validation-error#post-253598</link>
			<pubDate>Wed, 15 May 2013 02:09:22 +0000</pubDate>
			<dc:creator>Richard Vav</dc:creator>
			<guid isPermaLink="false">253598@https://legacy.forums.gravityhelp.com/</guid>
			<description>&#60;p&#62;Jacob,&#60;/p&#62;
&#60;p&#62;Can you paste a copy of the full code you are using for this from your functions file?
&#60;/p&#62;</description>
		</item>
		<item>
			<title>jacobdubail on "gform_enqueue_scripts injects script into iframe on validation error"</title>
			<link>https://legacy.forums.gravityhelp.com/topic/gform_enqueue_scripts-injects-script-into-iframe-on-validation-error#post-253284</link>
			<pubDate>Tue, 14 May 2013 20:53:26 +0000</pubDate>
			<dc:creator>jacobdubail</dc:creator>
			<guid isPermaLink="false">253284@https://legacy.forums.gravityhelp.com/</guid>
			<description>&#60;p&#62;Hi richardvav,&#60;/p&#62;
&#60;p&#62;Thanks a lot for your reply.  Sorry for my delayed response.&#60;/p&#62;
&#60;p&#62;I updated my script and am now getting the output you recommend.  I'm still seeing this script injected into the iframe, though.&#60;/p&#62;
&#60;p&#62;Here's a screenshot from my dev tools in Chrome: &#60;a href=&#34;http://i.imgur.com/MiJbGrF.png&#34; rel=&#34;nofollow&#34;&#62;http://i.imgur.com/MiJbGrF.png&#60;/a&#62;&#60;/p&#62;
&#60;p&#62;I'm still getting a &#34;jQuery is not defined&#34; error.&#60;/p&#62;
&#60;p&#62;Any idea how I can prevent scripts hooked to &#34;gform_enqueue_scripts&#34; from being inserted into the iframe?&#60;/p&#62;
&#60;p&#62;Thanks!&#60;/p&#62;
&#60;p&#62;-Jacob
&#60;/p&#62;</description>
		</item>
		<item>
			<title>Richard Vav on "gform_enqueue_scripts injects script into iframe on validation error"</title>
			<link>https://legacy.forums.gravityhelp.com/topic/gform_enqueue_scripts-injects-script-into-iframe-on-validation-error#post-246080</link>
			<pubDate>Fri, 10 May 2013 07:26:27 +0000</pubDate>
			<dc:creator>Richard Vav</dc:creator>
			<guid isPermaLink="false">246080@https://legacy.forums.gravityhelp.com/</guid>
			<description>&#60;p&#62;Hi Jacob,&#60;/p&#62;
&#60;p&#62;I am not sure scripts in the iframe is the problem, I tried using your placeholder function on an ajax form on my localhost install but I could only get it working by changing it like so&#60;br /&#62;
&#60;pre&#62;&#60;code&#62;&#38;lt;script&#38;gt;
jQuery(document).bind(&#38;#39;gform_post_render&#38;#39;,function(){
    jQuery(&#38;#39;#input_11_1&#38;#39;).attr(&#38;#39;placeholder&#38;#39;,&#38;#39;Name&#38;#39;);
});
&#38;lt;/script&#38;gt;&#60;/code&#62;&#60;/pre&#62;
&#60;p&#62;Regards,&#60;br /&#62;
Richard&#60;br /&#62;
--&#60;br /&#62;
Just another member of the community helping out where I can
&#60;/p&#62;</description>
		</item>
		<item>
			<title>jacobdubail on "gform_enqueue_scripts injects script into iframe on validation error"</title>
			<link>https://legacy.forums.gravityhelp.com/topic/gform_enqueue_scripts-injects-script-into-iframe-on-validation-error#post-244837</link>
			<pubDate>Thu, 09 May 2013 15:31:02 +0000</pubDate>
			<dc:creator>jacobdubail</dc:creator>
			<guid isPermaLink="false">244837@https://legacy.forums.gravityhelp.com/</guid>
			<description>&#60;p&#62;Hey guys,&#60;/p&#62;
&#60;p&#62;Any ideas?  Could you point me in the right direction?&#60;/p&#62;
&#60;p&#62;Thanks,&#60;br /&#62;
Jacob
&#60;/p&#62;</description>
		</item>
		<item>
			<title>jacobdubail on "gform_enqueue_scripts injects script into iframe on validation error"</title>
			<link>https://legacy.forums.gravityhelp.com/topic/gform_enqueue_scripts-injects-script-into-iframe-on-validation-error#post-228687</link>
			<pubDate>Sun, 28 Apr 2013 13:12:20 +0000</pubDate>
			<dc:creator>jacobdubail</dc:creator>
			<guid isPermaLink="false">228687@https://legacy.forums.gravityhelp.com/</guid>
			<description>&#60;p&#62;Hey guys,&#60;/p&#62;
&#60;p&#62;Here's a link to the site with the error: &#60;a href=&#34;http://hc.jacobdubail.com/&#34; rel=&#34;nofollow&#34;&#62;http://hc.jacobdubail.com/&#60;/a&#62;&#60;/p&#62;
&#60;p&#62;If you submit the form (toward the bottom of the page) without filling in any fields, you'll see that their is a &#34;jQuery is not defined&#34; error in the console.  jQuery is defined on the page, but not in the iFrame.  How can I prevent my script from being called/enqueued in the iFrame?&#60;/p&#62;
&#60;p&#62;Many thanks,&#60;br /&#62;
Jacob
&#60;/p&#62;</description>
		</item>

	</channel>
</rss>
