<?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: Create placeholder and keep placeholder while using ajax during validation</title>
		<link>https://legacy.forums.gravityhelp.com/topic/create-placeholder-and-keep-placeholder-while-using-ajax-during-validation</link>
		<description>Gravity Support Forums Topic: Create placeholder and keep placeholder while using ajax during validation</description>
		<language>en-US</language>
		<pubDate>Sat, 04 Apr 2026 04:51:53 +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/create-placeholder-and-keep-placeholder-while-using-ajax-during-validation" rel="self" type="application/rss+xml" />

		<item>
			<title>Richard Vav on "Create placeholder and keep placeholder while using ajax during validation"</title>
			<link>https://legacy.forums.gravityhelp.com/topic/create-placeholder-and-keep-placeholder-while-using-ajax-during-validation#post-337119</link>
			<pubDate>Fri, 21 Jun 2013 16:29:11 +0000</pubDate>
			<dc:creator>Richard Vav</dc:creator>
			<guid isPermaLink="false">337119@https://legacy.forums.gravityhelp.com/</guid>
			<description>&#60;p&#62;You might want to take a look at the following topic which is also about adding placeholders that work with ajax and remain when the form fails validation &#60;a href=&#34;http://www.gravityhelp.com/forums/topic/gform_enqueue_scripts-injects-script-into-iframe-on-validation-error&#34; rel=&#34;nofollow&#34;&#62;http://www.gravityhelp.com/forums/topic/gform_enqueue_scripts-injects-script-into-iframe-on-validation-error&#60;/a&#62;
&#60;/p&#62;</description>
		</item>
		<item>
			<title>daanvh on "Create placeholder and keep placeholder while using ajax during validation"</title>
			<link>https://legacy.forums.gravityhelp.com/topic/create-placeholder-and-keep-placeholder-while-using-ajax-during-validation#post-337055</link>
			<pubDate>Fri, 21 Jun 2013 15:34:34 +0000</pubDate>
			<dc:creator>daanvh</dc:creator>
			<guid isPermaLink="false">337055@https://legacy.forums.gravityhelp.com/</guid>
			<description>&#60;p&#62;Hi,&#60;/p&#62;
&#60;p&#62;This is not a question, but I have struggled a bit with this and thought that if others did as well, they don't need to purchase a gravity perks piece of software which is actually more expensive than the plugin itself. &#60;/p&#62;
&#60;p&#62;I ran into the problem that 1) I needed placeholders instead of labels for my field, and with that solved, I experienced that these placeholders were being removed on form validation errors when using ajax. &#60;/p&#62;
&#60;p&#62;Its not a very clean fix, but with a little help of javascript I managed to solve my problem.&#60;/p&#62;
&#60;p&#62;1) create a 'custom' validation error message in functions.php&#60;/p&#62;
&#60;p&#62;add the following code to functions.php:&#60;/p&#62;
&#60;pre&#62;&#60;code&#62;add_filter(&#38;quot;gform_validation_message_1&#38;quot;, &#38;quot;change_message&#38;quot;, 10, 2);
function change_message($message, $form){
  return &#38;quot;&#38;lt;script&#38;gt;placeholder();&#38;lt;/script&#38;gt;&#38;lt;p&#38;gt;This is your validation error text&#38;lt;/p&#38;gt;&#38;quot; . $form[&#38;quot;contact&#38;quot;];

}&#60;/code&#62;&#60;/pre&#62;
&#60;p&#62;Notice I included a javascript function, that's for later. Documentation on this: &#60;a href=&#34;http://www.gravityhelp.com/documentation/page/Gform_validation_message&#34; rel=&#34;nofollow&#34;&#62;http://www.gravityhelp.com/documentation/page/Gform_validation_message&#60;/a&#62;&#60;/p&#62;
&#60;p&#62;Now also put in the code that will add placeholder fields in GF (in functions.php):&#60;/p&#62;
&#60;pre&#62;&#60;code&#62;/* Copy this code in the functions.php file */
add_action(&#38;quot;gform_field_standard_settings&#38;quot;, &#38;quot;my_standard_settings&#38;quot;, 10, 2);
function my_standard_settings($position, $form_id){
    // Create settings on position 25 (right after Field Label)
    if($position == 25){
        ?&#38;gt;
        &#38;lt;li 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; 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; 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
    }
}

/* Copy this code in the functions.php file */
add_action(&#38;quot;gform_editor_js&#38;quot;, &#38;quot;my_gform_editor_js&#38;quot;);
function my_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
}

/* Copy this code in the functions.php file */
add_action(&#38;#39;gform_enqueue_scripts&#38;#39;,&#38;quot;my_gform_enqueue_scripts&#38;quot;, 10, 2);
function my_gform_enqueue_scripts($form, $is_ajax=false){
    ?&#38;gt;

&#38;lt;script&#38;gt;
    jQuery(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;#39;&#38;lt;?php echo $field[&#38;#39;placeholder&#38;#39;]?&#38;gt;&#38;#39;);
                &#38;lt;?php
            }
        }
        ?&#38;gt;
    });
    &#38;lt;/script&#38;gt;
    &#38;lt;?php
}&#60;/code&#62;&#60;/pre&#62;
&#60;p&#62;script source: &#60;a href=&#34;http://www.bogdan-nikolic.com/wordpress-gravity-forms-placeholder-which-works-with-ajax-validation/#comment-100&#34; rel=&#34;nofollow&#34;&#62;http://www.bogdan-nikolic.com/wordpress-gravity-forms-placeholder-which-works-with-ajax-validation/#comment-100&#60;/a&#62; (it says it works with ajax but for me it doesnt after form validation errors)&#60;/p&#62;
&#60;p&#62;Now lastly, add the function you added in the error message to your page: &#60;/p&#62;
&#60;pre&#62;&#60;code&#62;&#38;lt;script&#38;gt;

	function placeholder() {
	 $(&#38;#39;#input_1_1&#38;#39;).attr(&#38;#39;placeholder&#38;#39;,&#38;#39;Message *&#38;#39;);
     $(&#38;#39;#input_1_2&#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;I just created 2 for the fields with id input_1_1 and 1_2, but you can figure it out. &#60;/p&#62;
&#60;p&#62;Again, not a clean fix, but a fix. if anyone knows a cleaner solution (via functions.php) I am happy to hear from you.
&#60;/p&#62;</description>
		</item>

	</channel>
</rss>
