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 disables validation on required fields

  1. Hi.
    I was able to use the custom validation hook to write up a validation for a VIN field on my form. Works awesome, was able to include checks for caps, string length, certain characters - amazing.

    Problem is, when the function is in there, it disables validation on the other form fields... so as long as my custom validation is active, required fields don't show errors.
    When I remove it, my VIN field doesn't get checked (of course) but validations return for everything else.

    Does this mean that if I use custom validation, I have to define new checks for each field in my form?

    Posted 13 years ago on Tuesday March 22, 2011 | Permalink
  2. No, it should be specific to your field. It is probably how you implemented it, it probably wasn't done in a way that it is field specific. Post your custom code to http://www.pastie.org/ and provide a link to it so we can take a look at your custom validation code.

    Posted 13 years ago on Tuesday March 22, 2011 | Permalink
  3. http://www.pastie.org/1704099

    Here is the code that I am using for the VIN validation. It hits it with several checks as you'll see.

    The form is here:
    http://tinyurl.com/4tevcnb

    You will need to login as a test user (upper right link).
    u: anotherone
    p: password

    You can then see the GF. It creates a post to a CPT for Cars.
    All of the fields are required (except for description).
    Without my function above, all the other fields will show an error if left blank. With it, only the VIN field will show an error.

    Posted 13 years ago on Wednesday March 23, 2011 | Permalink
  4. Hi GrowthSpark,

    Remove the following line from you code and all should be well (ln 12).

    [php]
    $form = RGFormsModel::get_form_meta($form_id);
    Posted 13 years ago on Wednesday March 23, 2011 | Permalink
  5. Amazing.
    I was also missing

    $validation_result["is_valid"] = false;
    $form = $validation_result["form"];

    From right after the comment saying it was coming up... adding that in and commenting out that line you suggested and looks great.

    If you don't mind (because my brain works that way), what was that line I commented out doing? Was it hijacking that $form variable I needed for other purposes?

    One last thing... I got hasty when I entered the title of the post and the permalink to this topic is completely unhelpful - could you adjust it so it reads more like what the actual title of the post is?

    Thanks for ALL your help!

    Posted 13 years ago on Wednesday March 23, 2011 | Permalink
  6. http://www.pastie.org/1706525

    Actually... not quite out of the woods.
    With the code at the link above, everything errors out as expected and all my custom checks work properly, except...

    The whole form when filled out correctly now prints an error of: There was a problem with your submission. Errors have been highlighted below

    No field is highlighted or displays an error and the form does not submit.

    I tried removing each part of the check until I was left with a barebones piece of code and still gave the experience above.
    It wasn't until I removed the whole custom function that I was able to submit the form. Is something missing? I think all the required parts from the example hooks are in there.

    Posted 13 years ago on Thursday March 24, 2011 | Permalink
  7. Found the issue... I had a line in the wrong place...

    $validation_result["is_valid"] = false;

    Had to go as part of the error code in this block:

    $validation_result["is_valid"] = false;
    $form["fields"][0]["failed_validation"] = true;
    $form["fields"][0]["validation_message"] = "The Calculated VIN Check Digit is Incorrect";

    In the code above I had it only once above with the "set form validation to false block" like it is in the doc:
    http://www.gravityhelp.com/forums/topic/validate-input#post-19083

    Posted 13 years ago on Thursday March 24, 2011 | Permalink

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