Hide frontend form submission button based on user role

Support MB Frontend Submission Hide frontend form submission button based on user role

Viewing 2 posts - 1 through 2 (of 2 total)
  • Author
    Posts
  • #34137
    Prabakaran ShankarPrabakaran Shankar
    Participant

    Hi,

    I tried to hide the frontend form depending on the user role, for example for subscribers.

    In the form with MB conditional logic, with the option hide to hide the form for subscribers.

    But please help me to hide the submit button from the form.

    To solve this problem, I tried the following code

    `
    add_action( 'rwmb_frontend_before_submit_button', function( $config, $post_id ) {
    if ( 'job-post-title' === $config['7896'] ) {
    if( is_user_logged_in()){
    die;
    //return '';
    }
    }
    }, 10, 2 );

    `
    In the form, I have used several forms. The form 'job-post-title' is one of them and the first form ID.

    Please take a look and help me to conditionally hide the 'Submit' button.

    #34140
    Long NguyenLong Nguyen
    Moderator

    Hi,

    You can print some CSS/JS code to hide/remove the submit button at this action hook. For example:

    add_action( 'rwmb_frontend_before_submit_button', function( $config ) {
        if( !is_user_logged_in() ){ //check user role here
            ?>
            <style>
                .rwmb-button-wrapper.rwmb-form-submit {
                    display:  none;
                }
             </style>
            <?php
        }
    }, 10 );
Viewing 2 posts - 1 through 2 (of 2 total)
  • You must be logged in to reply to this topic.