taranarainf
(Pratit Asthana)
1
Hello Team,
I have the below script working fine for one field, just wondering how can I make it work for more than 1 field in the same form.
----------------------------------------------------
// To set min donation amount Rs. 500
add_filter( 'gform_field_validation_1_72', 'donate_minimum_validation', 10, 4 );
function donate_minimum_validation( $result, $value, $form, $field ) {
$min_amount = 500;
$donated = GFCommon::to_number( $value, 'INR' );
if ( $donated < $min_amount ) {
$result['is_valid'] = false;
$result['message'] = 'A minimum donation amount is ₹ '.$min_amount.' ';
}
return $result;
}
sacom
(Samuel Aguilera (Gravity Forms))
2
If you want to apply exactly the same validation, so no need to make any changes to your function. You can simply add more add_filter lines, example:
// To set min donation amount Rs. 500
add_filter( 'gform_field_validation_1_73', 'donate_minimum_validation', 10, 4 );
add_filter( 'gform_field_validation_1_72', 'donate_minimum_validation', 10, 4 );
function donate_minimum_validation( $result, $value, $form, $field ) {
$min_amount = 500;
$donated = GFCommon::to_number( $value, 'INR' );
if ( $donated < $min_amount ) {
$result['is_valid'] = false;
$result['message'] = 'A minimum donation amount is ₹ '.$min_amount.' ';
}
return $result;
}
As you can see above I added a new add_filter line before the one you have already, that will target field 73 in the same form.
You could also add more add_filter lines to target fields in other forms by changing 1 too.
system
(system)
Closed
3
This topic was automatically closed 30 days after the last reply. New replies are no longer allowed.