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.

Field Validation across Multiple Forms

  1. Hi,
    Is it possible to change field validation criteria for a specific field in multiple forms?
    For instance, I want to make it so that all quantity fields must contain a single whole number.
    Do I need to change the validation for EACH form which has a quantity field or can I do this for all forms at once?
    Thanks,
    Josh

    http://www.gravityhelp.com/documentation/page/Gform_field_validation

    Posted 11 years ago on Wednesday January 23, 2013 | Permalink
  2. You can validate all forms, one form, or one field in one form. To validate all forms, your quantity field would need to be the same ID in every form, which is not likely I don't think (if it is, then it's no problem to apply the same validation to the same field in every form.)

    However, you can write one function to force whole numbers, then add it to every form with a add_filter line for each form and field you want to validate. It's not optimal, especially if you are creating new forms all the time.

    The code you add to functions.php would look like this:

    // form 17, field 4
    add_filter("gform_field_validation_17_4", "force_whole_number", 10, 4);
    // form 12, field 20
    add_filter("gform_field_validation_12_20", "force_whole_number", 10, 4);
    // form 4, field 11
    add_filter("gform_field_validation_4_11", "force_whole_number", 10, 4);
    // etc
    // then add your function one time
    function force_whole_number ($result, $value, $form, $field){
      // your code here
    }
    Posted 11 years ago on Wednesday January 30, 2013 | Permalink