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.

Set all fields required via functions.php

  1. I am working on a form with 100+ fields, which is seperated in multiple pages.
    In order to be able to test the form more fast i set NO field required.

    If i want to set all fields required before release, I want to be able to do that via the functions.php.

    Here is an Example, based on this

    add_filter("gform_pre_render", "set_required");
    add_filter("gform_validation", "check_required");
    
    function set_required($form){
        foreach($form["fields"] as &$field){
         if ($field["type"] != "html")
        {
            $field["isRequired"] = true;}
    }
        return $form;
    }
    
    function check_required($validation_result){
        foreach($validation_result["form"]["fields"] as &$field){
         if ($field["type"] != "html")
          {
    
            if(GFFormDisplay::is_empty($field, $validation_result["form"]["id"])){
                $field["failed_validation"] = true;
                $field["validation_message"] = "This field is required.";
                $validation_result["is_valid"] = false;
            }
          }
        }
        return $validation_result;}

    The problem: it also sets my html fields to required, even that is not supposed to happen?
    See isRequired

    Posted 12 years ago on Wednesday May 9, 2012 | Permalink
  2. Follow up:

    I managed to leave out the html fields, but i can not proceed to the next page in my form...
    (I updated the code above accordingly)

    Posted 12 years ago on Wednesday May 9, 2012 | Permalink
  3. Rather than messing around with that, check out this cool tutorial for faster multi-page form testing:

    http://gravitywiz.com/2012/05/04/pro-tip-skip-pages-on-multi-page-forms/

    Posted 12 years ago on Wednesday May 9, 2012 | Permalink
  4. Thanks for the reply Rob,

    thats a "good to know" for the future! Thanks!

    So any advise how I could turn all my fields to required now in the backend without having to click each field? I started to build the form with fields not set to required.
    Please do not tell me my only choice is now to go through all the fields! (100+) :(

    Posted 12 years ago on Wednesday May 9, 2012 | Permalink

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