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.

Changed isRequired but still validating

  1. Hi.
    I would like to be able change some fields as required and not required based on specific pages and I am able to change the isRequired state, but it doesn't affect the form validation.
    Here is the code I used:

    add_filter("gform_pre_render", "set_required");
    function set_required($form){
    
        foreach($form["fields"] as &$field) {
    
    		$field["isRequired"] = false;
    
    	}
    
        return $form;
    }

    So I have a couple of fields set to be required in the form editor.
    How come the form is validating these fields when I have set all fields to be not required?

    Cordially
    Vayu

    Posted 12 years ago on Wednesday February 22, 2012 | Permalink
  2. Hi,

    I have a similar problem. I am trying to change the Required field in a PreRender filter. It doesn't seem to work.

    Jim

    Posted 12 years ago on Thursday March 8, 2012 | Permalink
  3. Come on guys - is it supposed to work ?

    A Yes or No response would at least give us a direction.

    Jim

    Posted 12 years ago on Tuesday March 13, 2012 | Permalink
  4. mikc03
    Member

    I have the same issue. Any response???????

    Thanks!

    Posted 11 years ago on Monday February 18, 2013 | Permalink
  5. mikc03
    Member

    Here is my code: http://pastebin.com/eHjUTA7F

    I tried to remove the zipcode field from the form. It was removed from the form (I do not see it in the form). But it was still going through validation (There was a problem with your submission. Errors have been highlighted below.)

    Then I also changed the field's isRequired to false. But The field is still going through validation.

    I'm not sure what is the issue here?

    btw, the zipcode field has the 'zip code' mask ( I removed the mask. it didn't help )

    Please let me know why this is not working.

    Thank you,
    RB

    Posted 11 years ago on Monday February 18, 2013 | Permalink
  6. Can you share a link to the page on your site where we can see your form please?

    Posted 11 years ago on Tuesday February 19, 2013 | Permalink
  7. mikc03
    Member

    Hi Chris,

    The site is not public. I'm developing on my machine.

    Is there a sample code for removing validation on a field?

    Do you see anything wrong with my code? I followed all the info I found in the developer docs and other responses in this forum.

    Thanks,
    RB

    Posted 11 years ago on Tuesday February 19, 2013 | Permalink
  8. How did you hide the zip code? This code seems to make the field not required and also does not let us force a validation error. How did you hide the zip code in the first place?

    Posted 11 years ago on Tuesday February 19, 2013 | Permalink
  9. mikc03
    Member

    See line 10 in http://pastebin.com/eHjUTA7F

    unset($form['fields'][$key]);

    Posted 11 years ago on Tuesday February 19, 2013 | Permalink
  10. mikc03
    Member

    Hello,

    Any update on this? Is this an existing issue?

    If so, please let me know if there is another way to get this working.

    Thank you,
    RB

    Posted 11 years ago on Thursday February 21, 2013 | Permalink
  11. mikc03
    Member

    seriously, no response???

    Posted 11 years ago on Friday February 22, 2013 | Permalink
  12. I've reached out to the dev team to see if they have any ideas for you here.

    Posted 11 years ago on Friday February 22, 2013 | Permalink
  13. Ok guys. Here I am with an answer for you.
    The gform_pre_render only fires when the form is displayed and not when the form is submitted. That is the reason fields are being marked as required (and appear to be required) when the form is displayed, but when the form is submitted, those fields are no longer marked as required. The solution is simple. In addition to using the gform_pre_render you will also need to use the gform_pre_validation. This is a relatively new hook available on GF 1.6.12 +, so make sure you are running the latest version. To make it more clear, following is the code that is needed to make this work:

    add_filter("gform_pre_render", "set_required");
    add_filter("gform_pre_validation", "set_required");
    function set_required($form){
    
        foreach($form["fields"] as &$field) {
            $field["isRequired"] = false;
        }
    
        return $form;
    }
    Posted 11 years ago on Friday February 22, 2013 | Permalink
  14. mikc03
    Member

    That worked!!!! :)

    Thank you very much for your help. I really appreciate it!

    Posted 11 years ago on Saturday February 23, 2013 | Permalink
  15. Thanks for the update mikc03.

    Posted 11 years ago on Saturday February 23, 2013 | Permalink

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