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.

Is there a better way to write this double entry validation?

  1. I'm building a registration form for a little league, and it's really important that the date of birth field is entered correctly, otherwise you have 13 year olds playing T-Ball. I want the users to enter the date of birth twice, then validate that both entries match.

    I managed to kludge together a custom validation that does this, but I don't like using the $_POST global variables. Is there a better way to write this?

    // Value of field 3_31 must match 3_6 and vice versa
    add_filter("gform_field_validation_3_31", "custom_validation", 10, 4);
    add_filter("gform_field_validation_3_6", "custom_validation", 10, 4);
    
    function custom_validation($result, $value, $form, $field){
    
    	$submission1 = $_POST['input_6'];
    	$submission2 = $_POST['input_31'];
    
        if($result["is_valid"] && ($submission1 != $submission2)){
            $result["is_valid"] = false;
            $result["message"] = "The date of birth fields don't match. Please make sure they are the same.";
        }
        return $result;
    }
    Posted 12 years ago on Monday January 9, 2012 | Permalink
  2. There's nothing wrong with doing it that way. Instead of $_POST you can use rgpost, like this, if you want:

    [php]
    	$submission1 = rgpost('input_6');
    	$submission2 = rgpost('input_31');

    That will do some sanitization for you. But your solution is perfectly acceptable.

    Posted 12 years ago on Wednesday January 11, 2012 | Permalink
  3. Okay, thanks Chris!

    Posted 12 years ago on Wednesday January 11, 2012 | Permalink

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