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.

Custom Validation affects all Gravity Forms on the Site

  1. http://pastie.org/1728462

    Above is the Custom Validation code for a VIN validation form I created.
    Works perfectly except that it tries to apply the validation against all Gravity Forms, is there a way to wrap the function or tag it such that it only affects form ID 1 and no other form?

    Posted 13 years ago on Monday March 28, 2011 | Permalink
  2. Change This:

    add_filter('gform_validation', 'custom_validation');

    To This:

    add_filter('gform_validation_1', 'custom_validation');

    You append the form id to the end of the gform_validation filter call.

    The documentation has been updated to reflect this. Most of the hook/filter calls work the same way and it is reflected in the documentation.

    Posted 13 years ago on Monday March 28, 2011 | Permalink
  3. Hm... the reason I asked the question in that way, however, was that I had tried that per another post in the forum to which I think you had responded.
    When I add that, it disables the custom validation completely.

    http://pastie.org/1728462

    So there the _1 is appended and it is as if the forms no longer see the filter.
    I have confirmed that I am indeed working with form ID 1.

    I'm running GF1.5, WP3.1, PHP 5.2.10 , MySQL 5.0.81.

    Is there another way to confine it to Form ID 1? Aside from that, the custom validation works well.

    Posted 13 years ago on Monday March 28, 2011 | Permalink
  4. I'll have a developer look at your code, the filter should work so it's probably something in the code itself.

    Posted 13 years ago on Monday March 28, 2011 | Permalink
  5. Wanted to see if there was anything found in the function I submitted or if you need me to try anything specific.

    Posted 13 years ago on Tuesday March 29, 2011 | Permalink
  6. Hi Growth,

    Sorry for the confusion. Apparently the gform_validation was one of the few hooks that did not have the ID specific version. We've added this to the core for the next release.

    In the meantime, you can do a simple conditional at the very beginning of the function that checks for the form ID and then returns the result if the submission is coming from a different form ID. Here is an example:

    [php]
    add_filter('gform_validation', 'custom_validation');
    function custom_validation($validation_result) {
    
    // set the form validation to false
    $form = $validation_result["form"];
    
    if($form['id'] != 1)
        return $validation_result;
    
    ... rest of your code ...
    Posted 13 years ago on Tuesday March 29, 2011 | Permalink
  7. http://pastie.org/1736358

    Looks like that worked!
    I pasted my function above and where I added the != so others could see the resolution.

    Posted 13 years ago on Wednesday March 30, 2011 | Permalink