PLEASE NOTE: These forums are no longer utilized and are provided as an archive for informational purposes only. All support issues will be handled via email using our support ticket system. For more detailed information on this change, please see this blog post.

gform_validation--total price field capped at certain $

  1. littler.chicken
    Member

    I hope this is possible with gform_validation but I've never used this and really don't know how to approach it. Have looked at the docs and am not making progress.

    What I have is a form which has two "products" on it--one is $7, one is $2. Theoretically unlimited products can be purchased but the maximum amount that can be charged is $25. So, if someone puts in 4 adults (the $7 product), the total price should be $25, not $28. Can I set up the gform validation to change the total price, and therefore charge that, instead of throwing an error message?

    Here is what I've muddled myself into at this point using the documentation and some forum searching, but it's not working:

    /** Gravity Forms Validation */
    add_filter("gform_validation_4", "rgc_totalvalidation");
    function rgc_totalvalidation($validation_result){
        $form = $validation_result["form"];
    	if($_POST['ginput_total_4'] >= 25 ){
    		if($is_valid)
                continue;
    		$validation_result["is_valid"] = false;
    		foreach($form["fields"] as &$field){
    			if($field["id"] == "input_4_4"){
                    $field["failed_validation"] = true;
                    $field["value"] = "25";
                    break;
    			}
    		}
    	}
    	//Assign modified $form object back to the validation result
        $validation_result["form"] = $form;
        return $validation_result;
    }

    The form in question is here.

    Posted 10 years ago on Friday May 17, 2013 | Permalink