我在表单的第 1 页上有一个字段 47,在第 3 页上有一个字段 55。如何在第 3 页创建 gform_validation 以在字段 47 < 字段 55 时提示错误消息?如果两个字段都在同一页面上,则下面的代码适用于验证,但不适用于多页。有什么想法吗?
谢谢!
// multi-page validation
add_filter( 'gform_validation', 'custom_validation' );
function custom_validation( $validation_result ) {
$form = $validation_result['form'];
// Financial Assets must be larger than Investment
if ( rgpost( 'input_47' ) < rgpost( 'input_55' ) ) {
// set the form validation to false
$validation_result['is_valid'] = false;
//finding Field with ID of 1 and marking it as failed validation
foreach( $form['fields'] as &$field ) {
//NOTE: replace 1 with the field you would like to validate
if ( $field->id == '34' ) {
$field->failed_validation = true;
$field->validation_message = 'Your Financial Assets (A) cannot be lower than your investment with us. Please fix the discrepancy.';
break;
}
}
}
//Assign modified $form object back to the validation result
$validation_result['form'] = $form;
return $validation_result;
}
我在他们的文档中找到了以下信息,但是我不确定如何在上面的代码中实现它。有什么线索吗?非常感谢!
// 3 - Get the current page being validated
$current_page = rgpost( 'gform_source_page_number_' . $form['id'] ) ? rgpost( 'gform_source_page_number_' . $form['id'] ) : 1;