Redirect
-
How can the user be redirected to a page after the contact form is submitted? Thanks!
-
Hello @rsmith4321,
I don’t have this feature but I can add it for you π We could do it through a new attribute in the shortcode, I could also add an option in the settings page, and of course, on top of this, also a filter.
Which way would be better for you right now?
The current behavior (or let’s say, if no page is chosen) is to redirect to the same page, and display a “Thank you” message (which can also be already changed through filters).
A shortcode attribute would work for me but a block setting would probably be easier for most users. I assumed it could be done with a filter I just didn’t know how.
Okay, done π I have published a new version of the Contact Form Block. There is a new setting available for Redirect URL. Please simply enter the URL, and when successful, the user will be sent to this page.
If you would like to play more, you can also handle the Redirect URL through this filter: https://meowapps.com/contact-form-block-faq-customization/#Override_the_Redirect_URL.
I was trying out the contact form it’s been a while. When you say you added this is it a shortcode attribute? Or do you need the below filter? If so how can this be modified to redirect to the url whenever the message sending is successful? Thanks!
add_filter( 'mcfb_redirect_url', function ( $url, $success, $error, $form ) { if ( $form['from'] === '[email protected]' ) return 'https://myfamily.com/hellomybrother'; return $url; }, 10, 4 );Hi @rsmith4321,
It’s not a shortcode, as it would be difficult to handle all the possibilities. It’s a filter, which is used exactly the way you thought it is π I think your question is more about where to write that code, right?
You can do it anywhere, in your functions.php (part of your theme), but I would advise you to do it with this plugin: https://ww.wp.xz.cn/plugins/code-snippets/. It’s the best way to add code to your WordPress.
Thanks I usually just add filters to the function.php of my child theme, I just thought you might have an undocumented shortcode attribute for a redirect. My actual question though was how to use the filter. In your example you have $form[‘from’] === ‘[email protected]’ then return the url. What would be the best way to change the code so any form submission redirects to the url? Would I just get rid of the if statement? Thanks!
Hi @rsmith4321! I am sorry for the late reply. Indeed, you just need to get rid of the condition and then it will always redirect to that page π Have you tried?
Hi Jordy thank you for your wonderful plugin (by the way I bought also Mediacleaner that I love so much). I can redirect to a specific page when the email is sent, but I would also like to redirect to a page if the message is not sent (errors in the form or something goes wrong). Is it possible?
Hi @maxonline and thanks you a lot π It’s a bit tricky, as those errors should be handled by the page containing the form. Why would you like that in fact?
The fact is:
I put the contact form at the bottom of my contact page. When the form finds an error while sending the message, it reloads the page and displays a message inside the form.
1) the sender must scroll at the end of the page to see the message (not everyone does)
2) the message is inside the form and not clearly visible, so It hought to address the visitor to an error page where he can try again or find other ways to send me a message.
Merci bien et salut.Max
The topic ‘Redirect’ is closed to new replies.