Gravity Forms Custom Validation ( bot check )

add_filter( 'gform_field_validation_1_12', 'custom_validation', 10, 4 );
add_filter( 'gform_field_validation_3_17', 'custom_validation', 10, 4 );
add_filter( 'gform_field_validation_6_17', 'custom_validation', 10, 4 );
add_filter( 'gform_field_validation_4_17', 'custom_validation', 10, 4 );
add_filter( 'gform_field_validation_5_18', 'custom_validation', 10, 4 );
add_filter( 'gform_field_validation_8_12', 'custom_validation', 10, 4 );
add_filter( 'gform_field_validation_10_12', 'custom_validation', 10, 4 );

function custom_validation( $result, $value, $form, $field ) {

    if ( $value != "beckwoodpress ready" ) {
        $result['is_valid'] = false;
        $result['message'] = "bot check failed";
    }
    return $result;
}

function add_custom_css_to_header() {
    ?>
    <style type="text/css">
        .bot_check {
            display: none;
        } 
        .logged-in .bot_check {
            display: block;
        }
    </style>
    <?php
}
add_action('wp_head', 'add_custom_css_to_header');


function add_bot_check_script() {
    ?>
    <script type="text/javascript">
        jQuery(document).ready(function($) {
            setTimeout(function(){
                $('.bot_check input').val('takefivesteps ready');
            }, 10000);
        });
    </script>
    <?php
}
add_action('wp_footer', 'add_bot_check_script');


Comments