Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
Gravity Forms custom validation: Ensure that the total on a product form is > 0
/**
* Ensure that the total on a product form is > 0
*/
add_filter('gform_validation', 'actonregister_validate_total');
function actonregister_validate_total($validation_result){
$form = $validation_result["form"];
$current_page = rgpost('gform_source_page_number_' . $form['id']) ? rgpost('gform_source_page_number_' . $form['id']) : 1;
foreach($form["fields"] as &$field){
$field_page = $field['pageNumber'];
if($field_page == $current_page && $field["type"] == "total" && rgpost("input_" . $field['id']) == "0"){
$validation_result["is_valid"] = false;
$field["failed_validation"] = true;
$field["validation_message"] = "You must select at least one price.";
break;
}
}
$validation_result["form"] = $form;
return $validation_result;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment