4

Kind of feel silly having to ask this but I cannot for the life of me get a success message to display after the redirect when the Contact Form submits.

I just am not sure how to call it in the template view.

I have tried various things like this:

{% set success = craft.config.get('successFlashMessage', 'contactform') %}

{% if success %}
  <div class="resp"><h3>{{ success }}</h3></div>
{% endif %}

But just cannot seem to grab it.

I did look at the documentation on Github and was not able to find it.

Brad Bell
  • 67,440
  • 6
  • 73
  • 143
Rockwell Rice
  • 509
  • 1
  • 5
  • 16
  • 1
    Is there a particular reason you want to use flash and not a redirect hidden input? https://github.com/pixelandtonic/ContactForm#redirecting-after-submit – Brad Bell Feb 03 '16 at 00:24
  • No, I just cannot get it to display a message either way, I would like it to stay on the same page but it does not absolutely have to. – Rockwell Rice Feb 03 '16 at 23:01
  • So you're saying even if you add a <input type="hidden" name="redirect" value="success">, you don't get redirected to /success? – Brad Bell Feb 03 '16 at 23:54
  • The redirect works fine, but there is no message, sorry if it is unclear what I was asking, I am trying to figure out how to display a "your message has been sent" type message on the screen when the message has been successfully sent. – Rockwell Rice Feb 04 '16 at 00:32
  • Ahh, if you're redirecting to a "success" template, then you can just hard code the "your message has been sent" message into the template. If there was a problem sending the email, the user is going to get an error page (either one supplied by you or a default Craft one) – Brad Bell Feb 04 '16 at 00:34
  • Right, I really wanted to just flash the message, remove the form and possibly add the name though and keep them on the same page. It's really not a big deal, I just seemed like one of those things that I thought would be simple at first and then I got totally bogged down doing and wanted to figure it out. – Rockwell Rice Feb 04 '16 at 00:41
  • Are you using AJAX to submit your form? Or are you just redirecting to the same page upon submission? – Mats Mikkel Rummelhoff Aug 11 '16 at 11:33

1 Answers1

4

You can see in the code for the plugin on GitHub that it sets a 'notice':

craft()->userSession->setNotice($settings->successFlashMessage);

As the official documentation mentions, this can later be grabbed with the following code:

{% set message = craft.session.getFlash('notice') %}

Then used as a normal message thereafter.

{{ message }}
Stephen Hamilton
  • 702
  • 3
  • 12