Php 重力形成和验证函数

Php 重力形成和验证函数,php,wordpress,Php,Wordpress,我使用多页重力表格。下面的代码检查第一页,我无法单击next按钮,因为该字段位于第二页,并且无效。我尝试了$current\u page==2,但它对我不起作用,我也不知道为什么 下面是代码的和平。如果有人能帮我一把,那就太好了 // validate 9 digit code // change here to your form ID add_filter('gform_validation_1', 'validate_code'); function validate_code($vali

我使用多页重力表格。下面的代码检查第一页,我无法单击
next
按钮,因为该字段位于第二页,并且无效。我尝试了
$current\u page==2
,但它对我不起作用,我也不知道为什么

下面是代码的和平。如果有人能帮我一把,那就太好了

// validate 9 digit code
// change here to your form ID
add_filter('gform_validation_1', 'validate_code');
function validate_code($validation_result){
        // this assumes the code is entered in field one on your form
        // change this input_ number if it's a different field
        if(!is_code_valid($_POST['input_18'])) {

        $validation_result['is_valid'] = false;
        foreach($validation_result['form']['fields'] as &$field){
            // field 1 is the field where we want to show the validation message
            if($field['id'] == 18){
                $field['failed_validation'] = true;
                                $field['validation_message'] = 'The code you entered is invalid: please try again.';
                break;
            }
        }
    }
    return $validation_result;
}

// use this function to validate codes
function is_code_valid($thiscode){
        // read all the codes in from the numbers.txt file
        // change the path here to the location of your file
        $codes = file('/htdocs/homepages/99/numbers.txt', FILE_IGNORE_NEW_LINES | FILE_SKIP_EMPTY_LINES);
        foreach($codes as $code){
                // compare the entered code to all codes in the file until we find a match
                if($thiscode == $code){
                        return TRUE;
                }
        }
        // if we did not have a match and are out of codes, return FALSE
        return FALSE;
}

// doing this here because the redirect URL does not support variables or shortcodes
// change the 70 here to your form ID
add_filter('gform_confirmation_1', 'valid_invitation_confirmation', 10, 4);
function valid_invitation_confirmation($confirmation, $form, $lead, $ajax){
        // customize this URL - I send the code in the query string
        $success_url = get_bloginfo('url') . '/?code=' . $lead[1];
        $confirmation = array('redirect' => $success_url);
        return $confirmation;
}

正如您所意识到的,您只希望在提交包含该字段的表单页面时验证该字段。以下是您如何检查的方法:

if( $field['pageNumber'] == GFFormDisplay::get_source_page($form['id'] ) ) {
    // run your custom validation here
}

这将进入$fields foreach循环中。您可以在上看到这一点。

第二页中的哪个函数是字段的验证?我添加了这样的内容:
if(!is_code_valid($_POST['input_18'])和¤t_page==2){//code}