Home / Admin / Conditionally Show the Submit Button
Duplicate Snippet

Embed Snippet on Your Site

Conditionally Show the Submit Button

This snippet will automatically show or hide the Submit button based on form field responses.

60+
Code Preview
php
<?php
/**
 * Conditionally show the submit button
 *
 * @link https://wpforms.com/developers/how-to-conditionally-show-the-submit-button/
 */
  
add_action( 'wp_head', function () { ?>
   
    <style>
  
    /* CSS hide submit button on page load */
    #wpforms-form-1000 .wpforms-submit-container .wpforms-submit {
            visibility:hidden;
        }
  
    #wpforms-form-1000 .wpforms-submit-container .wpforms-submit.show-submit {
            visibility:visible;
        }
   
    </style>
   
<?php } );
   
   
// Conditional logic for Submit button
function wpf_dev_form_redirect() {
    ?>
    <script>
        jQuery(function($){
            $( "form#wpforms-form-1000" ).click(function(){
                var selectedval = $( ".wpforms-form input[type='radio']:checked" ).val();
                if(selectedval == "No"){
                    window.location = "/thank-you";
                }
                if(selectedval == "Yes"){
                    $( ".wpforms-submit" ).addClass( "show-submit" );
                }
            });
        });
    </script>
    <?php
}
add_action( 'wpforms_wp_footer_end', 'wpf_dev_form_redirect', 10 );

Comments

Add a Comment