# If-Clauses / Validation

Hi all,

I just started with Gravity Forms. I currently setting up a form with the following problem: For setting up a company you must pay in at least USD 10 and at least 10% of the nominal capital. Therefore, there are 3 cases where the requirements are not met:

(1) Paid in capital is less than USD 10
(2) Paid in capital is less than 10% of the nominal capital
(3) Paid in capital is less than USD 10 and 10% of the nominal capital.

The first problem I figured out:

add_filter( ‘gform_field_validation_24_23’, ‘custom_validation’, 10, 4 );
function custom_validation( \$result, \$value, \$form, \$field ) {

``````if ( \$result['is_valid'] && intval( \$value ) < 10) {
\$result['is_valid'] = false;
\$result['message'] = 'The paid in capital must at least amount to USD 10';
}
return \$result;
``````

}

How can I add the two other if-clauses (i figured out, that i need elseif clauses)? The nominal capital is a form field, which can be determined by the user. It would be best if I could take the number from the nominal-capital field an multiply it by 10% and than compare it with “<” with my paid in capital field.

I tried something, but the error “There has been a critical error on this website.” appears. I don’t know how to solve it.

Whereas:
field 20 is nominal capital
field 21 is paid in capital

add_filter( ‘gform_field_validation_24_21’, ‘custom_validation_AK’, 10, 4 );
function custom_validation_AK( \$result, \$value, \$form, \$field, \$post_value, \$pre_value) {
\$pre_value = rgpost( ‘input_24_20’ );
\$post_value = \$pre_value * 0.1;

``````if ( \$result['is_valid'] ( \$value ) < 10 ) {
\$result['is_valid'] = false;
\$result['message'] = 'Paid in capital is less than USD 10';
}
``````

elseif ( \$result[‘is_valid’] < \$post_value) {
\$result[‘is_valid’] = false;
\$result[‘message’] = ‘Paid in capital is less than 10% of the nominal capital’;
}

elseif ( \$result[‘is_valid’] < \$post_value && \$result[‘is_valid’] < 10) {
\$result[‘is_valid’] = false;
\$result[‘message’] = ‘Paid in capital is less than USD 10 and 10% of the nominal capital’;
}

``````return \$result;
``````

}

Maybe somebody can point out, what’s wrong.

Your system’s error log will tell you exactly what the actual critical error is, you can also enable debugging in WordPress to see it: Debugging in WordPress | WordPress.org

Just at first glance at your code, you’re supplying too many arguments within the callback function on line 2. You should only have \$result, \$value, \$form, and \$field there.

1 Like

This topic was automatically closed 30 days after the last reply. New replies are no longer allowed.