1

In the front-end, I create a form and submit the data to backend. In the controller, if got some errors, I would like to redirect to the previous page with some information.

  • 2
    Hello Dave. You've tagged this question with sprout-seo but your questions sounds like a more general form question. Sprout SEO can help you manage general redirects for pages that change URLs on your site, but redirecting on success or errors in forms should be handled within the form workflow itself. Can you update your question to be more specific about how you have built and are submitting your form? Is this a Craft Front End Form? Is the controller you mention a custom controller that you wrote? Any code examples about how you are currently trying to handle redirects? – Ben Parizek Nov 15 '18 at 12:40
1

If you're using the Pixel & Tonic Contact Form plugin then there is a way to set your redirect using {{ redirectInput('contact/thanks') }} as seen here: https://github.com/craftcms/contact-form

However, I've just noticed you've tagged this question with plugin-sproutseo, but I'm not aware of that plugin interacting with contact forms in any way.

To more specifically try to answer your question, firstly to redirect and pass some information, I have used query params before so I've set my redirect link to be /thankyou?name={{ formstuff.name }} so I can access the user's name with:

{% set name = craft.app.request.getParam('name') %}

Now when it comes to redirecting back to the user's previous page, have a read of this answer below. It's a few years old, but it'd potentially still give you an option to resolve your issue: https://craftcms.stackexchange.com/a/13488/5845

EDIT: After a look at some other questions, I've noticed this one has an almost identical wording so this one should be marked as duplicate. See dupe below:

How to redirect the page with params?

| improve this answer | |

Not the answer you're looking for? Browse other questions tagged or ask your own question.