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 using PHP class

  1. Hi,

    My form has ID "7". I'm trying to fire a custom validation on submit but the validation function doesn't appear to be running.

    I believe this might be to do with the fact that I'm working with a PHP Class which means I'm doing the following

    add_filter('gform_validation_7', array( $this, 'validate_me' ) );

    rather than simply...

    add_filter('gform_validation_7', 'validate_me' );

    The validate me method does not get called when I submit my form. I know this because I've placed

    exit()

    within the body of that method. No dice.

    Any help much appreciated.

    Posted 5 years ago on Thursday January 17, 2013 | Permalink
  2. I'll bring this to the attention of the development team for their input. I've never seen anyone try to use gform_validation like this.

    Posted 5 years ago on Thursday January 17, 2013 | Permalink
  3. Great stuff. Happy to send website code to a private email but not able to post on forum.

    If it helps the gform_pre_render_7 filter seems to work perfectly using the same method:

    add_filter('gform_pre_render_7', array( $this, 'populate_select_fields' ) );

    The apply_filters call in form_display.php seems quite complex. Maybe this is where is issue lies...? Maybe it's my code?

    Help is appreciated.

    Posted 5 years ago on Thursday January 17, 2013 | Permalink
  4. In addition it's worth mentioning that the only reason I was trying to apply custom validation is because the dropdown field I marked as "required" in the GF admin area was not being picked up as invalid during form submission.

    The process was:

    1) Form is rendered and dropdown A is populated with values form a Custom Post Type.
    2) When the user selects from dropdown A, some javascript runs which populates dropdown B with the correct values (these are from another post type).
    3) When the form is submitted with the default value (eg: "Please select") Gravity forms allows the form to be submitted even though it should fail validation due to no value being selected.

    I've now resolved the issue which lies in the GF's admin interface for Form creation. The issue was that by default even though I'd removed all but 1 value for the dropdown B, GF's was setting a "value" attribute on the option element. This caused it to pass validation as there was always value selected.

    To solve this, in the form builder admin area you must select "Show values" on the "Choices" field and then ensure that the contents of the "Value" field is entirely blank. I feel this should be made more obvious.

    So in essence my issue is solved in the short term. Nonetheless I would appreciate feedback from your developers on how I might be able to add_filter using a Class method.

    Posted 5 years ago on Thursday January 17, 2013 | Permalink
  5. Your code looks right and the filter should fire. The only question is where you are placing it. The $this variable is only defined inside your class, so you need to make sure that line of code is being called inside one of your class' methods.
    I will be glad to take a look at your file if you send it to alex@rocketgenius.com (please include a link to this post)

    Posted 5 years ago on Thursday January 17, 2013 | Permalink
  6. Alex - many thanks. I've sent you the code.

    Posted 5 years ago on Friday January 18, 2013 | Permalink