We have a GravityForm we use for customer intake with a Terms & Conditions checkbox. The validation is currently failing even when a user checks the box, not allowing them to check out.
We’ve confirmed the checkbox is the issue by adding the following filter to log validation results:
add_filter( 'gform_validation_1', 'log_form_1_validation_errors', 1);
function log_form_1_validation_errors( $validation_result ) {
if (!$validation_result['is_valid']) {
$validation_failures = [];
foreach ($validation_result['form']['fields'] as $field) {
if ($field->failed_validation) {
$validation_failures[] = [
'field_id' => $field->id,
'label' => $field->label,
'message' => $field->validation_message,
];
}
}
write_log("FORM 1 VALIDATION FAILURE: PAGE {$validation_result['failed_validation_page']}: " . var_export([
'current_user_email' => wp_get_current_user()->user_email,
'fields' => $validation_failures,
'post_values' => $_POST,
], true));
}
return $validation_result;
}
This results in entries like the following in our logs:
FORM 1 VALIDATION FAILURE: PAGE 6: array (
'current_user_email' => 'redacted@example.com',
'fields' =>
array (
0 =>
array (
'field_id' => 308,
'label' => 'Terms & Conditions',
'message' => 'This field is required.',
),
),
'post_values' => array( "redacted" )
)
Can anyone please help us debug this issue?