skip to Main Content

WordPress Code Snippets


How to Add Custom Validation in Gravity Forms for Accuracy

Implement custom validation for a specific field in a Gravity Form.

add_filter('gform_field_validation_1_2', 'codebykp_custom_validation', 10, 4);
function codebykp_custom_validation($result, $value, $form, $field) {
    if ($field->id == 2 && !filter_var($value, FILTER_VALIDATE_EMAIL)) {
        $result['is_valid'] = false;
        $result['message'] = 'Please enter a valid email address.';
    }
    return $result;
}


I’m a WordPress developer with 10+ years of experience in WooCommerce and custom plugins. I combine technical expertise with design flair to help you create standout, user-friendly websites. Let’s transform your digital presence!

Best WordPress Hosting
Back To Top
Search