3

I'd like to be able to display incidental messages on the front end, such as for 'thank-you' content and success/error messages after form submissions. However, I'd like to do this without polluting the URLs with extra segments... Is there a standard solution for this?

1 Answer 1

2

Sure, cookies would be the way to go here if you don't want extra segments. Cookies Plus looks like it could make this easy for you (though there are some negative reviews ... no harm in giving it a shot of course, it would save you from writing this custom or adding PHP into your templates).

First, your form would redirect to forms/submit/success.

In that template you'd put:

{exp:cookie_plus:set name="flash_message" value="Your entry was submitted." seconds="10"}
{redirect="forms/submit"}

Then in your forms/submit template:

{exp:cookie_plus:get name="flash_message"}
{if cookie}
    <p class="message success">{cookie}</p>
{/if}
{/exp:cookie_plus:get}

You can get more elaborate if you want to conditionally check for different cookie names that represent different kinds of messages, etc.

1
  • 2
    Thanks for this Derek. Your answer prompted me to realise that Stash can solve this problem in basically the same way using {exp:stash:set name="flash_message" scope="user" save="yes"}Message{/exp:stash:set} and setting the stash_cookie_expire config variable. Commented Jan 29, 2013 at 18:42

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

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