<?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_validation example</title>
		<link>https://legacy.forums.gravityhelp.com/topic/gform_validation-example</link>
		<description>Gravity Support Forums Topic: Gform_validation example</description>
		<language>en-US</language>
		<pubDate>Sat, 04 Apr 2026 16:13:54 +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_validation-example" rel="self" type="application/rss+xml" />

		<item>
			<title>Alex Cancado on "Gform_validation example"</title>
			<link>https://legacy.forums.gravityhelp.com/topic/gform_validation-example#post-30155</link>
			<pubDate>Fri, 15 Jul 2011 16:54:19 +0000</pubDate>
			<dc:creator>Alex Cancado</dc:creator>
			<guid isPermaLink="false">30155@https://legacy.forums.gravityhelp.com/</guid>
			<description>&#60;p&#62;You were close... you forgot to &#34;return true;&#34; from your validate_mcss() function.&#60;/p&#62;
&#60;pre&#62;&#60;code&#62;function validate_mcss($mcss) {
    $mcss = trim($mcss);
// check mcss value
    if ($mcss != &#38;quot;MCSS5&#38;quot;) {
        // MCSS is not valid - must match MCSS5
        return false;
    }
    return true;
}&#60;/code&#62;&#60;/pre&#62;</description>
		</item>
		<item>
			<title>vlinkdave on "Gform_validation example"</title>
			<link>https://legacy.forums.gravityhelp.com/topic/gform_validation-example#post-30128</link>
			<pubDate>Fri, 15 Jul 2011 14:48:51 +0000</pubDate>
			<dc:creator>vlinkdave</dc:creator>
			<guid isPermaLink="false">30128@https://legacy.forums.gravityhelp.com/</guid>
			<description>&#60;p&#62;Perhaps I need to trim the passed value before I do the comparison in the function??&#60;/p&#62;
&#60;p&#62;Didn't seem to make a difference when I tried it  :-(&#60;/p&#62;
&#60;p&#62;Any thoughts on what I should try next??&#60;/p&#62;
&#60;p&#62;... dave&#60;/p&#62;
&#60;pre&#62;&#60;code&#62;function validate_mcss($mcss) {
    $mcss = trim($mcss);
// check mcss value
    if ($mcss != &#38;quot;MCSS5&#38;quot;) {
        // MCSS is not valid - must match MCSS5
        return false;
    }

    }&#60;/code&#62;&#60;/pre&#62;</description>
		</item>
		<item>
			<title>vlinkdave on "Gform_validation example"</title>
			<link>https://legacy.forums.gravityhelp.com/topic/gform_validation-example#post-30119</link>
			<pubDate>Fri, 15 Jul 2011 13:13:27 +0000</pubDate>
			<dc:creator>vlinkdave</dc:creator>
			<guid isPermaLink="false">30119@https://legacy.forums.gravityhelp.com/</guid>
			<description>&#60;p&#62;I'm trying to follow the example but can't seem to validate my form field correctly.  &#60;/p&#62;
&#60;p&#62;On the very simple form at &#60;a href=&#34;http://www.selyestresssolutions.com/e-learning-resources/registration/&#34; rel=&#34;nofollow&#34;&#62;http://www.selyestresssolutions.com/e-learning-resources/registration/&#60;/a&#62; I'm checking the form fields based on a cssClass to find the &#34;ARAMCO&#34; field that needs validation and then checking if the value entered is &#34;MCSS5&#34;. Unfortunately the form continues to give me the error message that the value inserted is not correct.&#60;/p&#62;
&#60;p&#62;Can you point me to my logic or coding error? I think I'm close :-)&#60;/p&#62;
&#60;p&#62;Thx... dave&#60;/p&#62;
&#60;pre&#62;&#60;code&#62;// Registration form MCSS validation
add_filter(&#38;#39;gform_validation&#38;#39;, &#38;#39;custom_validation&#38;#39;);
function custom_validation($validation_result) {

    $form = $validation_result[&#38;quot;form&#38;quot;];

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

        if(strpos($field[&#38;#39;cssClass&#38;#39;], &#38;#39;validate-mcss&#38;#39;) === false)
            continue;

        $field_value = rgpost(&#38;quot;input_{$field[&#38;#39;id&#38;#39;]}&#38;quot;);
        $is_valid = validate_mcss($field_value);

        if($is_valid)
            continue;

        $validation_result[&#38;#39;is_valid&#38;#39;] = false;
        $field[&#38;#39;failed_validation&#38;#39;] = true;
        $field[&#38;#39;validation_message&#38;#39;] = &#38;#39;The MCSS you have entered is not valid.&#38;#39;;
    }
// update the form in the validation result with the form object you modified
$validation_result[&#38;quot;form&#38;quot;] = $form;
    return $validation_result;
}

function validate_mcss($mcss) {
    // check mcss value
    if ($mcss != &#38;quot;MCSS5&#38;quot;) {
        // MCSS is not valid - must match MCSS5
        return false;
    }

    }&#60;/code&#62;&#60;/pre&#62;</description>
		</item>
		<item>
			<title>Alex Cancado on "Gform_validation example"</title>
			<link>https://legacy.forums.gravityhelp.com/topic/gform_validation-example#post-28483</link>
			<pubDate>Fri, 24 Jun 2011 11:17:10 +0000</pubDate>
			<dc:creator>Alex Cancado</dc:creator>
			<guid isPermaLink="false">28483@https://legacy.forums.gravityhelp.com/</guid>
			<description>&#60;p&#62;Thanks for the better example! I have replaced our existing example with yours (with a minor change to make it even more useful).&#60;br /&#62;
As far as setting the main message, you can use the gform_validation_message filter to change it. &#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;I agree it would be nicer to set it right from the gform_validation hook. I will keep that in mind for the next versions.
&#60;/p&#62;</description>
		</item>
		<item>
			<title>bristweb on "Gform_validation example"</title>
			<link>https://legacy.forums.gravityhelp.com/topic/gform_validation-example#post-28456</link>
			<pubDate>Fri, 24 Jun 2011 00:20:34 +0000</pubDate>
			<dc:creator>bristweb</dc:creator>
			<guid isPermaLink="false">28456@https://legacy.forums.gravityhelp.com/</guid>
			<description>&#60;p&#62;one other thought.  it would be nice if you could override the text&#60;/p&#62;
&#60;p&#62;&#60;em&#62;&#34;There was a problem with your submission. Errors have been highlighted below.&#34;&#60;/em&#62;&#60;/p&#62;
&#60;p&#62;and replace / append with your own custom message.  some validation will not be related to a specific field...
&#60;/p&#62;</description>
		</item>
		<item>
			<title>bristweb on "Gform_validation example"</title>
			<link>https://legacy.forums.gravityhelp.com/topic/gform_validation-example#post-28455</link>
			<pubDate>Fri, 24 Jun 2011 00:18:07 +0000</pubDate>
			<dc:creator>bristweb</dc:creator>
			<guid isPermaLink="false">28455@https://legacy.forums.gravityhelp.com/</guid>
			<description>&#60;p&#62;&#60;a href=&#34;http://www.gravityhelp.com/documentation/page/Gform_validation&#34; rel=&#34;nofollow&#34;&#62;http://www.gravityhelp.com/documentation/page/Gform_validation&#60;/a&#62;&#60;/p&#62;
&#60;p&#62;the example code you offer here is a little confusing&#60;/p&#62;
&#60;pre&#62;&#60;code&#62;&#38;lt;?php
add_filter(&#38;#39;gform_validation&#38;#39;, &#38;#39;custom_validation&#38;#39;);
function custom_validation($validation_result){

    // set the form validation to false
    $validation_result[&#38;quot;is_valid&#38;quot;] = false;
    $form = $validation_result[&#38;quot;form&#38;quot;];

    // specify the first field to be invalid and provide custom validation message
    $form[&#38;quot;fields&#38;quot;][0][&#38;quot;failed_validation&#38;quot;] = true;
    $form[&#38;quot;fields&#38;quot;][0][&#38;quot;validation_message&#38;quot;] = &#38;quot;This field is invalid!&#38;quot;;

    // update the form in the validation result with the form object you modified
    $validation_result[&#38;quot;form&#38;quot;] = $form;

    return $validation_result;

}
?&#38;gt;&#60;/code&#62;&#60;/pre&#62;
&#60;p&#62;your example would override all other validations and only perform the one validation example you give.  the following would be a better example&#60;/p&#62;
&#60;pre&#62;&#60;code&#62;&#38;lt;?php
add_filter(&#38;#39;gform_validation&#38;#39;, &#38;#39;custom_validation&#38;#39;);
function custom_validation($validation_result){

    if($_POST[&#38;#39;input_1&#38;#39;] == 86){ //supposing we don&#38;#39;t want input 1 to be a value of 86
	// set the form validation to false
    $validation_result[&#38;quot;is_valid&#38;quot;] = false;
    $validation_result[&#38;quot;form&#38;quot;][&#38;quot;fields&#38;quot;][0][&#38;quot;failed_validation&#38;quot;] = true;
    $validation_result[&#38;quot;form&#38;quot;][&#38;quot;fields&#38;quot;][0][&#38;quot;validation_message&#38;quot;] = &#38;quot;This field is invalid!&#38;quot;;
	}
    return $validation_result;

}
?&#38;gt;&#60;/code&#62;&#60;/pre&#62;</description>
		</item>

	</channel>
</rss>
