拉莫斯之舞
您需要使用gform_field_validation验证过滤器才能在表单之前执行此类validation提交。此外,我们需要使用 PHP 的 preg_match 函数和 regex 来确保我们只从全名输入值中获取字母。只需将此代码添加到您的活动主题functions.php 文件中即可:(代码已测试且正常工作)add_filter( 'gform_field_validation', function ( $result, $value, $form, $field ) { if ( $field->type == 'name' ) { // Input values $fullName = rgar( $value, $field->id . '.3' ); if ( empty( $fullName )) { $result['is_valid'] = false; $result['message'] = empty( $field->errorMessage ) ? __( 'This field is required. Please enter a complete name.', 'gravityforms' ) : $field->errorMessage; } else if (preg_match('/[A-Za-z].*[0-9]|[0-9].*[A-Za-z]/', $fullName)) { //check for letters only $result['is_valid'] = false; $result['message'] = empty( $field->errorMessage ) ? __( 'Full name must ony contains letters.', 'gravityforms' ) : $field->errorMessage; } else { $result['is_valid'] = true; $result['message'] = ''; } } return $result; //return results}, 10, 4 );