Prevent forms from rendering submit button

Support MB User Profile Prevent forms from rendering submit buttonResolved

Viewing 9 posts - 1 through 9 (of 9 total)
  • Author
    Posts
  • #41977
    pluginovenpluginoven
    Participant

    In using the mb_user_profile_info shortcode, is there a way to prevent the shortcode factory from rendering the submit button? I see we can provide a unique ID for the submit button using the id_submit attribute. At the moment I am forcing the ID to be blank using `id_submit="", and then changing the info.php file located under src/Forms as follows:

    protected function submit_button() {
    		if(empty( $this->config['id_submit'] )){
    			return;
    		}
    		?>
    		<div class="rwmb-field rwmb-button-wrapper rwmb-form-submit">
    			<div class="rwmb-input">
    				<button type="submit" class="rwmb-button" id="<?= esc_attr( $this->config['id_submit'] ) ?>" name="rwmb_profile_submit_info" value="1"><?= esc_html( $this->config['label_submit'] ) ?></button>
    			</div>
    		</div>
    		<?php
    	}

    Would rather not modify the plugin's core files. A filter or attribute to prevent the submit button from rendering would be useful.

    #41983
    PeterPeter
    Moderator

    Hello,

    There isn't an option to remove the button in the user frontend form. You can use some custom CSS code to hide it on your site.

    #42098
    pluginovenpluginoven
    Participant

    The CSS workaround would work if I could assign a class to the submit button. Is this possible? An ID can be assigned using the id_submit but then either:
    a) custom CSS to hide multiple submit buttons by their unique ID if they exist on the same page would need to be created. or
    b) a new id_class attribute would need to be added to the plugin allowing one CSS class definition to be used to hide the submit button.

    of course, something like id_submit="hidden_submit" could be used in conjunction with a single CSS ID definition, but then, when multiple forms are used on the same page (or in different tabs on the same page), multiple elements with the same ID would exist in the DOM. Not good.

    As many times before, I will modify the plugin to get around this issue for the immediate need and would be happy to submit a pull request.

    #42099
    pluginovenpluginoven
    Participant

    The suggested modifications to src/Forms/info.php are as follows:
    1. Add the class_submit attribute to the $config.

    $config = shortcode_atts( [
    			...
    			// Appearance options.
    			...
    			'id_password'       => 'user_pass',
    			'id_password2'      => 'user_pass2',
    			'id_submit'         => 'submit',
    			'class_submit'         => '',  // Add class_submit attribute
    			...
    ], $config );

    2. add $this->config['class_submit'] to the button class:

    protected function submit_button() {
    		?>
    		<div class="rwmb-field rwmb-button-wrapper rwmb-form-submit">
    			<div class="rwmb-input">
    				<button type="submit" class="rwmb-button <?= esc_attr( $this->config['class_submit'] ); ?>" id="<?= esc_attr( $this->config['id_submit'] ) ?>" name="rwmb_profile_submit_info" value="1"><?= esc_html( $this->config['label_submit'] ) ?></button>
    			</div>
    		</div>
    		<?php
    	}
    #42109
    PeterPeter
    Moderator

    Hello,

    Instead of modifying the code, you can just create a <div> tag with a class and wrap the frontend shortcode inside the div. For example:

    <div class="my-custom-form">
    [mb_frontend_form id='my-custom-fields' post_fields='title,content']
    </div>

    Then easy to use the following selector to select the submit button

    .my-custom-form .rwmb-form-submit button {
    your CSS code here
    }
    #42116
    pluginovenpluginoven
    Participant

    Yes. this is a valid solution.
    This issue can be marked as resolved.
    Thank you.

    #43728
    pluginovenpluginoven
    Participant

    Again we are faced with this issue
    While there is a rwmb_frontend_submit_button filter for forms created with mb_frontend_form, there is no such filter for mb_user_profile_info (which can also be used on the front end.

    This is a missing feature. Where can a pull request be submitted?

    #43729
    pluginovenpluginoven
    Participant

    src/Forms/info.php:

    protected function submit_button() {
    		$submit_button = '<div class="rwmb-field rwmb-button-wrapper rwmb-form-submit">
    			<div class="rwmb-input">
    				<button type="submit" class="rwmb-button" id="'.esc_attr( $this->config['id_submit'] ).'" name="rwmb_profile_submit_info" value="1">'.esc_html( $this->config['label_submit'] ).'</button>
    			</div>
    		</div>';
    		$submit_button = apply_filters( 'rwmb_profile_submit_button', $submit_button, $this->config );
    		echo $submit_button;
    	}

    usage:

    add_filter( 'rwmb_profile_submit_button', 'fix_frontend_submit_button', 20 , 2 );
    function fix_frontend_submit_button( $submit_button, $config ) {
    		$is_complete = get_user_meta( $config['user_id'], 'is_complete', true );
    		if($is_complete){
    			$submit_button = '';
    		}
    		return $submit_button;
    	}

    src/Forms/Base.php: function render()

    ...
    do_action( 'rwmb_profile_before_form', $this->config );
    
    		$form = '<form class="rwmb-form mbup-form" method="post" enctype="multipart/form-data" id="' . esc_html( $this->config['form_id'] ) . '">';
    		$form = apply_filters( 'rwmb_profile_form', $form, $this->config );
    		echo $form;
    ...

    usage:

    add_filter( 'rwmb_profile_form', 'fix_frontend_profile_form', 20 , 2 );
    function fix_frontend_profile_form( $form, $config ) {
    		$is_complete = get_user_meta( $config['user_id'], 'is_complete', true );
    		if($is_complete){
    			$form = str_replace('method="post"', 'disabled', $form);
    		}
    		return $form;
    	}
    #43750
    PeterPeter
    Moderator

    Thanks for your feedback.

    I've forwarded it to the development team to consider supporting a filter hook for the submit button form in the user profile forms.

Viewing 9 posts - 1 through 9 (of 9 total)
  • You must be logged in to reply to this topic.