• Resolved johnnyenglish14

    (@johnnyenglish14)


    Hi there,
    I have a login form and I want after the user successfully logs in for it to show a “login successful” message while hiding the form then after the message auto-closes the page will redirect to where I need it to.
    Currently that’s an either-or situation in the submission behaviour as far as I can see. I tried setting up both a hide behaviour and redirect but it just does the first one only. I see that the redirect has the ability to also hide the form but opens a new tab. I want this to happen all in one tab.

    So basically, user logs in -> success message for a few seconds and hiding form -> redirect to another page.

    Thanks.

Viewing 10 replies - 1 through 10 (of 10 total)
  • Plugin Support Kris – WPMU DEV Support

    (@wpmudevsupport13)

    Hi @johnnyenglish14

    I hope you are doing well today.

    This will be not possible as Submission Behavior:
    – Inline Message
    – Redirect user to a URL
    – Hide form
    cannot work together. Only via conditional logic.

    I pinged our SLS Team to review your query and see if we can help in this matter.

    Kind Regards,
    Kris

    Plugin Support Kris – WPMU DEV Support

    (@wpmudevsupport13)

    Hi again

    You can try this snippet as a mu-plugin:

    Must Use Plugins

    Submission behavior should be hide form where you can enter a message too. The redirect will be handled by the snippet.

    add_action( 'wp_footer', function(){
    	global $post;
    	if( ! $post instanceof WP_Post || ! has_shortcode( $post->post_content, 'forminator_form' ) ) {
    		return;
    	}
    	?>
    	<script type="text/javascript">
    	jQuery( document ).ready( function($) {
    		setTimeout(function() {
    			$('.forminator-custom-form').trigger('after.load.forminator');
    		},100);
    
    		$(document).on('after.load.forminator', function(event, form_id) {
    			jQuery('form.forminator-custom-form').on('forminator:form:submit:success', function (e, formData) {
    				var form_id = e.target.id;
    				if ( form_id == 'forminator-module-2636' ) {
    					setTimeout(function(){						
    						var url = "https://domain.com/page/";						
    						window.open(url, '_self');						
    					}, 1000);
    				}
    			});
    		});
    	});
    	</script>
    	<?php
    }, 9999 );

    In the code, you need to change the form ID from 2636 to your form ID and the redirect URL should be changed from https://domain.com/page/ to your redirect URL. 1000 is 1 second.

    Kris

    Thread Starter johnnyenglish14

    (@johnnyenglish14)

    Thanks for the response.
    I changed the things that needed to. The form ID, that’s the number I get in the shortcode right? It’s 762 for my login form.
    I created a php file in the mu-plugins folder and it shows up as one in the installed plugins so that part worked.

    Unfortunately it’s not doing anything non standard. I tried on a couple of browsers and in incognito just in case but it just gave my hide form success message and no redirect.

    Could there be something wrong with this code or have I missed something, or some other setting needs to be set for it to work?

    Plugin Support Amin – WPMU DEV Support

    (@wpmudev-support2)

    hello @johnnyenglish14 ,

    I’m incredibly sorry we missed your response.

    Can you export your form so we can check it closer? See here how to export it https://wpmudev.com/docs/wpmu-dev-plugins/forminator/#import-export
    Use pastebin.com to share it with us or dropbox-like service.

    kind regards,
    Kasia

    Thread Starter johnnyenglish14

    (@johnnyenglish14)

    Ok here you are: https://pastebin.com/uwRUKfra

    I should point out I’m using this login form inside a popup for the main part so the form can pop up on any page. I do also have a separate page where the login form is embedded (as Elementor widget) but also doesn’t work on that. I have tried the different behaviour options like ajax/page caching etc and none of them made it work.

    It would also be good to reload them to the page they were on instead of specific page (I have a {hidden-1} field with Embed URL set, which is what I use for current redirect). Thanks.

    Plugin Support Nithin – WPMU DEV Support

    (@wpmudevsupport11)

    Hi @johnnyenglish14,

    I’m afraid, the snippet shared isn’t meant to work inside the popup. The code will only work if you add the shortcode to a page via Page Builder.

    I tested by adding the form shortcode on a page by using the Shortcode widget in Elementor and that works fine.

    It would also be good to reload them to the page they were on instead of specific page (I have a {hidden-1} field with Embed URL set, which is what I use for current redirect). .

    Could we know whether using the form inside the Shortcode widget helps cover your need so that we could check whether the snippet could be tweaked further based on your above use case?

    Looking forward to your response.

    Kind Regards,

    Nithin

    Thread Starter johnnyenglish14

    (@johnnyenglish14)

    Thanks for the reply.

    While as I did say I had a separate page with it in I did just try it as an actual widget and not a Forminator widget and then it worked on the separate page. The problem is if it can’t work inside the popup (or wherever the form is really) it’s kind of useless to me.

    I just deleted this part and it worked inside the popup:

    if( ! $post instanceof WP_Post || ! has_shortcode( $post->post_content, 'forminator_form' ) ) {
    		return;
    }

    Is there a reason this part is necessary or something?

    Anyway can this be adjusted to make it work on reloading to same page (but minus the #sign-in that the popup creates)? As mentioend I did add a embed url hidden field and I know that takes out that # part. I would assume it would be easiest to use that.

    Thanks so much for the help.

    Plugin Support Nebu John – WPMU DEV Support

    (@wpmudevsupport14)

    Hi @johnnyenglish14,

    We have pinged our SLS team for more insights on this and we’ll update you here once we have more feedback on this as soon as possible.

    Kind Regards,
    Nebu John

    Plugin Support Nebu John – WPMU DEV Support

    (@wpmudevsupport14)

    Hi @johnnyenglish14,

    The SLS team confirmed it’s safe to remove the mentioned code as we do check the form ID as well. I hope that helps to make the workaround useful when placing the form in a pop-up.

    Please feel free to get back to us if you need any further assitance.

    Kind Regards,
    Nebu John

    Thread Starter johnnyenglish14

    (@johnnyenglish14)

    Hiya cheers for that. I was able to figure out how to get it to reload the same page instead of going to specific url and also cuts out the extra stuff after the # symbol (can be changed).
    For anyone else that comes across this here is my final code:

    <?php
    add_action( 'wp_footer', function(){
    	global $post;
    	?>
    	<script type="text/javascript">
    	jQuery( document ).ready( function($) {
    		setTimeout(function() {
    			$('.forminator-custom-form').trigger('after.load.forminator');
    		},100);
    
    		$(document).on('after.load.forminator', function(event, form_id) {
    			jQuery('form.forminator-custom-form').on('forminator:form:submit:success', function (e, formData) {
    				var form_id = e.target.id;
    				if ( form_id == 'forminator-module-1288' ) {
                      	let url = window.location.href.split('#')[0]
    					setTimeout(function(){											
    						window.open(url, '_self');						
    					}, 1000);
    				}
    			});
    		});
    	});
    	</script>
    	<?php
    }, 9999 );
Viewing 10 replies - 1 through 10 (of 10 total)
  • The topic ‘Login Form redirect after x time’ is closed to new replies.