<?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: Custom validation help needed</title>
		<link>https://legacy.forums.gravityhelp.com/topic/custom-validation-help-needed</link>
		<description>Gravity Support Forums Topic: Custom validation help needed</description>
		<language>en-US</language>
		<pubDate>Sat, 25 Apr 2026 02:38:31 +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/custom-validation-help-needed" rel="self" type="application/rss+xml" />

		<item>
			<title>cazwilson on "Custom validation help needed"</title>
			<link>https://legacy.forums.gravityhelp.com/topic/custom-validation-help-needed#post-22484</link>
			<pubDate>Tue, 05 Apr 2011 00:17:57 +0000</pubDate>
			<dc:creator>cazwilson</dc:creator>
			<guid isPermaLink="false">22484@https://legacy.forums.gravityhelp.com/</guid>
			<description>&#60;p&#62;Thank you, David, for your help via email, and your fix:&#60;/p&#62;
&#60;blockquote&#62;&#60;p&#62;Just add this line:&#60;br /&#62;
&#60;code&#62;$validation_result[&#38;#39;form&#38;#39;] = $form;&#60;/code&#62;&#60;br /&#62;
...directly before returning the $validation_result, like so: &#60;a href=&#34;http://grab.by/9MHO&#34; rel=&#34;nofollow&#34;&#62;http://grab.by/9MHO&#60;/a&#62;
&#60;/p&#62;&#60;/blockquote&#62;
&#60;p&#62;That worked perfectly!&#60;/p&#62;
&#60;p&#62;Your assistance has been wholehearted and has really saved my day.
&#60;/p&#62;</description>
		</item>
		<item>
			<title>cazwilson on "Custom validation help needed"</title>
			<link>https://legacy.forums.gravityhelp.com/topic/custom-validation-help-needed#post-22147</link>
			<pubDate>Thu, 31 Mar 2011 06:06:59 +0000</pubDate>
			<dc:creator>cazwilson</dc:creator>
			<guid isPermaLink="false">22147@https://legacy.forums.gravityhelp.com/</guid>
			<description>&#60;p&#62;OK. Carl. I have sent the access info via the Priority Support form.&#60;/p&#62;
&#60;p&#62;Thanks,&#60;br /&#62;
Carolyn
&#60;/p&#62;</description>
		</item>
		<item>
			<title>Carl Hancock on "Custom validation help needed"</title>
			<link>https://legacy.forums.gravityhelp.com/topic/custom-validation-help-needed#post-21928</link>
			<pubDate>Tue, 29 Mar 2011 10:51:31 +0000</pubDate>
			<dc:creator>Carl Hancock</dc:creator>
			<guid isPermaLink="false">21928@https://legacy.forums.gravityhelp.com/</guid>
			<description>&#60;p&#62;@cazwilson Without being able to see the form it's real difficult to determine the issue.
&#60;/p&#62;</description>
		</item>
		<item>
			<title>cazwilson on "Custom validation help needed"</title>
			<link>https://legacy.forums.gravityhelp.com/topic/custom-validation-help-needed#post-21880</link>
			<pubDate>Mon, 28 Mar 2011 20:18:43 +0000</pubDate>
			<dc:creator>cazwilson</dc:creator>
			<guid isPermaLink="false">21880@https://legacy.forums.gravityhelp.com/</guid>
			<description>&#60;p&#62;Hi David,&#60;/p&#62;
&#60;p&#62;The multi-page and non-visible fixes are working - thank you!&#60;/p&#62;
&#60;p&#62;I am still not getting an error message, though. The form isn't unusual in any way except I have added two column css classes to some fields (not the ABN one).&#60;/p&#62;
&#60;p&#62;I tested the field as Required - the standard &#34;This field is required&#34; message appears if the field is empty. But if I add less than 11 digits, or a wrong number, the same thing happens. The error message appears at the top of the page, but no error message on the field.&#60;/p&#62;
&#60;p&#62;I tested it without Required checked, too. No success.&#60;/p&#62;
&#60;p&#62;I have copied and pasted your code without editing. And applied the validate-abn css class to the field. There is no error if the number is correct, too, btw. So that is working.&#60;/p&#62;
&#60;p&#62;I'm stumped at what to look at next.&#60;/p&#62;
&#60;p&#62;The form's website is currently password protected during development. Otherwise I could post the URL here.
&#60;/p&#62;</description>
		</item>
		<item>
			<title>David Smith on "Custom validation help needed"</title>
			<link>https://legacy.forums.gravityhelp.com/topic/custom-validation-help-needed#post-21820</link>
			<pubDate>Mon, 28 Mar 2011 15:07:26 +0000</pubDate>
			<dc:creator>David Smith</dc:creator>
			<guid isPermaLink="false">21820@https://legacy.forums.gravityhelp.com/</guid>
			<description>&#60;p&#62;Hi Cazwilson,&#60;/p&#62;
&#60;p&#62;Here is some updated code that addresses the multi-page and non-visible scenarios: &#60;a href=&#34;http://pastie.org/1727617&#34; rel=&#34;nofollow&#34;&#62;http://pastie.org/1727617&#60;/a&#62;&#60;/p&#62;
&#60;p&#62;I was unable to recreate the first issue you reported. The field in error is correctly labeled in my testing of this code. I used the sample ABN number provided on the following page to test:&#60;/p&#62;
&#60;p&#62;&#60;a href=&#34;http://www.ato.gov.au/businesses/content.asp?doc=/content/13187.htm&#34; rel=&#34;nofollow&#34;&#62;http://www.ato.gov.au/businesses/content.asp?doc=/content/13187.htm&#60;/a&#62;
&#60;/p&#62;</description>
		</item>
		<item>
			<title>cazwilson on "Custom validation help needed"</title>
			<link>https://legacy.forums.gravityhelp.com/topic/custom-validation-help-needed#post-21725</link>
			<pubDate>Mon, 28 Mar 2011 00:15:04 +0000</pubDate>
			<dc:creator>cazwilson</dc:creator>
			<guid isPermaLink="false">21725@https://legacy.forums.gravityhelp.com/</guid>
			<description>&#60;p&#62;Hi David,&#60;/p&#62;
&#60;p&#62;Thank you so much for your time.&#60;/p&#62;
&#60;p&#62;On a single page form with no conditional logic it does works in so much as displaying this message:&#60;br /&#62;
&#34;There was a problem with your submission. Errors have been highlighted below&#34;.&#60;br /&#62;
But there is no field specific error message.&#60;/p&#62;
&#60;p&#62;Also, if the field is not visible - that is, on another page of a multi-page form, or hidden due to conditional logic, the above error message appears - because nothing has been entered in the field.&#60;/p&#62;
&#60;p&#62;Would it be possible to work around these issues?&#60;/p&#62;
&#60;p&#62;Thanks again.&#60;br /&#62;
CW
&#60;/p&#62;</description>
		</item>
		<item>
			<title>David Smith on "Custom validation help needed"</title>
			<link>https://legacy.forums.gravityhelp.com/topic/custom-validation-help-needed#post-21668</link>
			<pubDate>Sun, 27 Mar 2011 09:35:14 +0000</pubDate>
			<dc:creator>David Smith</dc:creator>
			<guid isPermaLink="false">21668@https://legacy.forums.gravityhelp.com/</guid>
			<description>&#60;p&#62;Hi Cazwilson,&#60;/p&#62;
&#60;p&#62;Paste the following code into your theme's functions.php file: &#60;a href=&#34;http://pastie.org/1721964&#34; rel=&#34;nofollow&#34;&#62;http://pastie.org/1721964&#60;/a&#62;&#60;/p&#62;
&#60;p&#62;Instead of validating these by the field ID, I've updated the code to validate by a CSS class. Any field you'd like to validate with the ABN function, just add this to the CSS class property: &#34;validate-abn&#34;. Here is an exampe: &#60;a href=&#34;http://grab.by/9I0b&#34; rel=&#34;nofollow&#34;&#62;http://grab.by/9I0b&#60;/a&#62;
&#60;/p&#62;</description>
		</item>
		<item>
			<title>cazwilson on "Custom validation help needed"</title>
			<link>https://legacy.forums.gravityhelp.com/topic/custom-validation-help-needed#post-21434</link>
			<pubDate>Thu, 24 Mar 2011 21:55:05 +0000</pubDate>
			<dc:creator>cazwilson</dc:creator>
			<guid isPermaLink="false">21434@https://legacy.forums.gravityhelp.com/</guid>
			<description>&#60;p&#62;Hi, &#60;/p&#62;
&#60;p&#62;I need to apply an ABN (Australian Business Number) validation formula to 3 fields in my form, and am having trouble getting it to function.&#60;/p&#62;
&#60;p&#62;I have applied this validation code - &#60;a href=&#34;http://www.clearwater.com.au/code&#34; rel=&#34;nofollow&#34;&#62;http://www.clearwater.com.au/code&#60;/a&#62; - to hook samples and this is what I have come up with:&#60;/p&#62;
&#60;pre&#62;&#60;code&#62;&#38;lt;?php

// Application form ABN validation

add_filter(&#38;#39;gform_validation_2&#38;#39;, &#38;#39;custom_validation&#38;#39;);
function custom_validation($validation_result){

function ValidateABN($abn)
{
    $weight = array(10, 1, 3, 5, 7, 9, 11, 13, 15, 17, 19);
    $form = $validation_result[&#38;quot;form&#38;quot;];

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

        // ABN field ID
        if($field[&#38;#39;id&#38;#39;] = input_2_16&#124;&#124;input_2_26&#124;&#124;input_2_49)
            continue;

    // strip anything other than digits
    $abn = preg_replace(&#38;quot;/[^\d]/&#38;quot;,&#38;quot;&#38;quot;,$abn);

    // check length is 11 digits
    if (strlen($abn)!=11) {
        // ABN is not valid - must have 11 digits
        return false;
    }

    // apply ato check method 

    $sum = 0;
    for ($i=0;$i&#38;lt;11;$i++) {
        $digit = $abn[$i] - ($i ? 0 : 1);
        $sum += $weight[$i] * $digit;
    }
    return ($sum % 89)==0;

   $field[&#38;#39;failed_validation&#38;#39;] = true;
   $field[&#38;#39;validation_message&#38;#39;] = &#38;#39;The ABN you have entered is not valid.&#38;#39;;

   $validation_result[&#38;#39;is_valid&#38;#39;] = false;
   $validation_result[&#38;#39;form&#38;#39;] = $form;

   break;
}

    // we end by returning the validation result
    return $validation_result;
}
}

?&#38;gt;&#60;/code&#62;&#60;/pre&#62;
&#60;p&#62;where the form ID is 2 and the fields to be validated are input_2_16, input_2_26 and input_2_49.&#60;/p&#62;
&#60;p&#62;Filling in a wrong number is not setting off an error message.&#60;/p&#62;
&#60;p&#62;Help with this would be greatly appreciated.
&#60;/p&#62;</description>
		</item>

	</channel>
</rss>
