Hi,
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.
I have applied this validation code - http://www.clearwater.com.au/code - to hook samples and this is what I have come up with:
<?php
// Application form ABN validation
add_filter('gform_validation_2', 'custom_validation');
function custom_validation($validation_result){
function ValidateABN($abn)
{
    $weight = array(10, 1, 3, 5, 7, 9, 11, 13, 15, 17, 19);
    $form = $validation_result["form"];
	foreach($form['fields'] as &$field){
        // ABN field ID
        if($field['id'] = input_2_16||input_2_26||input_2_49)
            continue;
    // strip anything other than digits
    $abn = preg_replace("/[^\d]/","",$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<11;$i++) {
        $digit = $abn[$i] - ($i ? 0 : 1);
        $sum += $weight[$i] * $digit;
    }
    return ($sum % 89)==0;
   $field['failed_validation'] = true;
   $field['validation_message'] = 'The ABN you have entered is not valid.';
   $validation_result['is_valid'] = false;
   $validation_result['form'] = $form;
   break;
}
    // we end by returning the validation result
    return $validation_result;
}
}
?>where the form ID is 2 and the fields to be validated are input_2_16, input_2_26 and input_2_49.
Filling in a wrong number is not setting off an error message.
Help with this would be greatly appreciated.
 
				
