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.

$0 Donation causes form to disappear

  1. clustrmedia

    I have set up a donation form with the Paypal Add-On. I have set the donation field to be a User-Defined Price. The problem we have run into is if the user submits the form with $0 in the donation field, the form disappears. It doesn't show the normal error handling message like if you were to enter a negative value like -$1.00. What do I need to change to make it display the error message instead of making the form disappear?

    The form can be viewed here -

    Posted 4 years ago on Tuesday March 27, 2012 | Permalink
  2. That sucks that you really have people try to donate $0 to you. I mean, $0.00 is a valid amount, technically. I'm thinking you might need to use this filter to potentially check for a $0.00 amount and then maybe set it to a minimum of $1.00.

    Posted 4 years ago on Wednesday March 28, 2012 | Permalink
  3. clustrmedia

    Thanks Rob. We don't want to change the amount the user enters in the donation field. We just want the error message to display if they enter $0. Is there a filter for that? I'm not that skilled in PHP so I may need a bit more help.

    Posted 4 years ago on Wednesday March 28, 2012 | Permalink
  4. 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:

    //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.";
        return $validation_result;
    Posted 4 years ago on Thursday March 29, 2012 | Permalink
  5. clustrmedia

    Worked like a charm! Thank you very much!

    Posted 4 years ago on Friday March 30, 2012 | Permalink
  6. RIght on right on! Glad to help.

    Posted 4 years ago on Saturday March 31, 2012 | Permalink

This topic has been resolved and has been closed to new replies.

Support Tickets

Open A New Support Ticket
 Open A New Priority Support Ticket *

* Developer license holders only