phpformsgravity

Using Gravity Forms "gform_field_validation"


I want to validate the field using gform_field_validation I found this documentation but not that helpful

    add_filter("gform_field_validation", "custom_validation", 10, 4);
    function custom_validation($result, $value, $form, $field){
       $number = GFCommon::to_number($value,"");

       if (($field["id"] == 1) && ($field["id"] == 1))
           if( ($result["is_valid"]) && ($number >= 1000) && ($number <= 1999)){
               $result["is_valid"] = false;
               $result["message"] = "INCORRECT NUMBER";
           }
       return $result;
    }

Any suggestions will be appreciated


Solution

  • @GDB Many thanks, here I found the solution as below

    add_filter("gform_field_validation", "custom_validation", 10, 4);
    
    function custom_validation($result, $value, $form, $field){
    
       if (($field["id"] == 1) && ($field["id"] == 1))
           if( ((intval($value) > 999) || (intval($value) < 2000)){
               $result["is_valid"] = false;
               $result["message"] = "INCORRECT NUMBER";
           }
       return $result;
    }