gform_gfcf_custom_empty_field_check

Description

This filter allows other add-ons to add their inputs in Conversational Forms.

Usage

Applies to all forms:

add_filter(  'gform_gfcf_custom_empty_field_check', 'your_function_name' );

Parameters

The filter has no parameters.

Examples

1. Use gform_pre_render to render the filter for the Pipe Add-On.

The pipe field is a hidden input element that is not counted as a filled field by default when determining whether the form is empty. Adding this filter for the Pipe field will prompt Conversational Forms to verify whether it is filled or empty, ensuring it is included in the form’s validation process.

add_filter( 'gform_pre_render', 'add_custom_gform_js_filters' );
function add_custom_gform_js_filters($form) {
    ?>
    <script type="text/javascript">
        document.addEventListener('DOMContentLoaded', function() {
            // Custom function to add to the gform_gfcf_custom_empty_field_check filter.
            function customBypassValidations(bypassFunctions) {
                // The pipe field is a hidden input element and, by default, hidden elements
                // arent counted as filled fields when checking if the form is empty.
                // Adding a filter for the pipe field will force Conversational Forms
                // to check if the field is empty or not.
                bypassFunctions.push( [
                    // check if the input is of pipe recorder
                    (input) => input.closest('.gfield--input-type-pipe_recorder'),
                    // set to false so internally is not bypassed as a hidden input
                    (input) => false
                ]);
                return bypassFunctions;
            }

            // Add filter to the gform object
            if(typeof gform !== 'undefined') gform.addFilter('gform_gfcf_custom_empty_field_check', customBypassValidations);
        });
    </script>
    <?php
    return $form;
}

Placement

This code can be used in the functions.php file of the active theme, a custom functions plugin, a custom add-on, or with a code snippets plugin.

See also the PHP section in this article: Where Do I Put This Code?

Source Code

This filter is located in /assets/js/src/theme/components/form/validation.js

Since

The filter was added in Conversational Forms 1.5.0