Gravity Forms custom validation: Ensure that the total on a product form is > 0
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/** | |
* 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