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.

Reade form values in custom validation

  1. hi, I'm referring to this custom validation sample:

    add_filter('gform_validation', 'custom_validation');
    function custom_validation($validation_result){
    
        // set the form validation to false
        $validation_result["is_valid"] = false;
        $form = $validation_result["form"];
    
        // specify the first field to be invalid and provide custom validation message
        $form["fields"][0]["failed_validation"] = true;
        $form["fields"][0]["validation_message"] = "This field is invalid!";
    
        // update the form in the validation result with the form object you modified
        $validation_result["form"] = $form;
    
        return $validation_result;
    
    }

    How do I access the fields actual value to validate it?

    $form["fields"][0]["value"] doesn't seem to work?

    where in the docs do I find the list of possibilities for this $form["fields"] array?

    thanks

    Posted 13 years ago on Thursday April 7, 2011 | Permalink
  2. Hi Gbotica,

    Here is an in-depth usage of the gform_validation hook that covers retrieving the submitted value for the field.

    http://pastie.org/1768573

    The value is available in the $_POST and can be access using the following key format: "input_{field_id}".

    Posted 13 years ago on Thursday April 7, 2011 | Permalink
  3. In addition, we've written a walk through for using this the gform_validation hook:

    http://bit.ly/foLW6t

    Posted 13 years ago on Thursday April 7, 2011 | Permalink
  4. Thanks for your help.

    I've got it now, except can't seem to get chckbox values (I know they only pass when checked), but even so, I can't get the value.

    $_POST['input_16.1'], or should it be: $_POST['input_16.1'][0]

    Posted 13 years ago on Friday April 8, 2011 | Permalink
  5. Hi Gbotica,

    For checkbox values it would be $_POST['input_{field_id}_{choice_index}']. Given your example it would be: $_POST['input_16_1'].

    Also, just a handy little tip... you can use php's print_rr function to output all of the values (and their corresponding keys) like so: print_rr($_POST).

    Posted 13 years ago on Friday April 8, 2011 | Permalink