Gotcha, no problem, this should work for you. Place this into your theme's functions file. This is using the gform_validation hook that is found here:
http://www.gravityhelp.com/documentation/page/Gform_validation
<?php
//Form ID
add_filter('gform_validation_3', 'custom_validation');
function custom_validation($validation_result){
//finding field with ID of 1 and making sure quantity is greater than 0
foreach($validation_result["form"]["fields"] as &$field){
//NOTE: the field you would like to validate
if($field["id"] == "4"){
//Base prices are retrieved using "input_FIELDID_2"
$base_price = GFCommon::to_number($_POST["input_3_2"]);
//Quantities are retrieved using "input_FIELDID_3"
$quantity = $_POST["input_3_3"];
//fails validation if quantity is not a positive integer or if price is equal to $0
if($quantity <= 0 || $base_price == 0){
$validation_result["is_valid"] = false;
$field["failed_validation"] = true;
$field["validation_message"] = "Please enter a valid amount.";
}
break;
}
}
return $validation_result;
}
?>
Posted 12 years ago on Thursday March 29, 2012 |
Permalink