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.

Validation of a number field

  1. I have a form which asks whether a registrant is requesting vegetarian meal(s). If the answer is yes, then 3 number fields appear asking how many meals for adults, older children, and younger children. If the registrant checks "yes" to request vegetarian meals but then doesn't modify any of the 3 number fields, I want the form to prompt the registrant to choose a non-zero number in at least 1 of those 3 number fields. So I've created a number field (id 39) in the form (id 12) which totals the 3 number fields, and added the following code to functions.php

    add_filter("gform_field_validation_12_39", "custom_validation", 10, 4);
    function custom_validation($result, $value, $form, $field){
        if($result["is_valid"] && intval($value) == 0){
            $result["is_valid"] = false;
            $result["message"] = "Total vegetarian meals must be greater than zero";
        }
        return $result;
    }

    But it doesn't generate an error message if I leave all the 3 number fields as zero. What am I missing?

    Posted 7 years ago on Wednesday March 20, 2013 | Permalink
  2. Can you please provide a link to the page on your site where the form is embedded so we can take a look at it?

    Posted 7 years ago on Thursday March 21, 2013 | Permalink
  3. The form is here:
    http://bethshalombozeman.org/community/community-passover-seder

    Posted 7 years ago on Friday March 22, 2013 | Permalink
  4. I received a message "Registration is now closed. If you are interested in attending, please contact Jake Werner directly at 581-9277." when trying to access the form on that page. If you need help with this, please put a copy of the form on a page without scheduling the end date so we can take a look at it. Thank you.

    Posted 7 years ago on Sunday March 24, 2013 | Permalink