<p>You could append a query string on your redirect url that you can then query for in your template. I've used this to display different messages for a new post or an edited post.</p>

<p><code>&lt;input type="hidden" name="redirect" value="my-photos?message=photo-added"&gt;</code></p>

<pre><code>{% set message = craft.request.getQuery( 'message' ) %}

{% if message|length and message == 'photo-added' %}
  &lt;p&gt;Thank's for uploading your image&lt;/p&gt;
{% endif %}
</code></pre>

<p>To use fields from the saved entry you could use a plugin and watch for the <a href="https://craftcms.com/docs/plugins/events-reference#entries-onSaveEntry" rel="nofollow">entries.onSaveEntry</a> event that will fire when using the Guest Entries plugin. </p>

<pre><code>craft()-&gt;on( 'entries.onSaveEntry', function( Event $event ){
  // Grab the entry from post request
  $entry = $event-&gt;params['entry'];

  // Add some conditionals so you only perform the redirect for the section you're posting to in the front end

  $name = $entry-&gt;getContent()-&gt;fieldName;

  // Render a template and pass the $name in
  //( not sure how to do this? )
});
</code></pre>

CC BY-SA 3.0
2016-05-23T16:54:54.273Z
Thanks Luke. Would it be possible with the second approach to return to the same page and output a message there?

I guess all I want to do is say "Thanks for getting in touch". Would rather avoid query strings but if it's the easiest way...
André Goldstein
CC BY-SA 3.0
2016-05-23T16:58:52.473Z
Realised I missed out the name part of your question - updated my answer
Luke Pearce
CC BY-SA 3.0
2016-05-23T17:00:46.187Z
Thanks so much Luke for your updated answer, I will give it a whirl!
André Goldstein
CC BY-SA 3.0
2016-05-23T17:06:03.230Z
Hang on, I've got the template render thing wrong
Luke Pearce
CC BY-SA 3.0
2016-05-23T17:35:05.043Z
You're a machine, @LukePearce.
Brad Bell
CC BY-SA 3.0
2016-05-23T18:32:30.853Z
Thanks again Luke, I'd be interested in seeing about how to pass in the template but have opted for the far simpler query method. I'm guessing there is no way to query the forms submission natively then with saveEntries.
André Goldstein
CC BY-SA 3.0
2016-10-12T17:20:42.270Z
@LukePearce I don't think your "Render a template and pass the $name in" will actually work, because of the redirect that will take place following it. See my answer for an alternate.
Tim Kelty
CC BY-SA 3.0
2016-05-23T16:44:04.803Z
2016-05-23T18:06:33.893Z
2016-05-23T18:06:33.893Z
Luke Pearce
<p>From what I can tell, Luke's answer wont actually work, because ultimately after the saveEntry event, <code>GuestEntries</code> will <code>redirectToPostedUrl</code>, which will lose any variables you have passed.</p>

<p>You options are explained here: <a href="https://craftcms.stackexchange.com/questions/2210/is-it-possible-to-setroutevariables-when-redirecting-after-a-successful-form-sub">Is it possible to setRouteVariables when redirecting after a successful form submission?</a></p>

<p>Example using SESSION:</p>

<pre><code>// custom/CustomPlugin.php
craft()-&gt;on('guestEntries.onSuccess', function($event) {
    $entry = $event-&gt;params['entry'];
    craft()-&gt;httpSession-&gt;add('lastEntryId', $entry-&gt;id);
});

// custom/CustomVariable.php
public function getLastEntry()
{
    if (craft()-&gt;httpSession-&gt;get('lastEntryId'))
    {
        $entryId = craft()-&gt;httpSession-&gt;get('lastEntryId');
        $entry   = craft()-&gt;entries-&gt;getEntryById($entryId);

        craft()-&gt;httpSession-&gt;destroy('lastEntryId');
    }

    return $entry ?? null;
}

// In your success template
{% if lastEntry %}
    &lt;h2&gt;Review "{{ lastEntry.title }}" submission successful.&lt;/h2&gt;
{% endif %}
</code></pre>

CC BY-SA 3.0
2016-10-12T14:17:01.163Z
2016-10-12T17:18:08.027Z
2017-04-13T12:51:00.200Z
Tim Kelty
<p>I'm currently using the Guest Entries plugin with a front-end form to accept contact form submissions.</p>

<p>I'm just wondering if it's possible to output a message on a successful form being saved?</p>

<p>In an ideal world this might include the name of the submitter but failing that just a plain message informing the user that the form has been submitted.</p>

<p>(Previously I've been able to access the craft.request.getPost('name') but I don't think this works when using this plugin?</p>

<p>Thanks!</p>

<guest-entries>
Is it possible to output message on successful save with Guest Entries?
# Is it possible to output message on successful save with Guest Entries?

(Asked by: username_0 on 2016-05-23)

I'm currently using the Guest Entries plugin with a front-end form to accept contact form submissions.

I'm just wondering if it's possible to output a message on a successful form being saved?

In an ideal world this might include the name of the submitter but failing that just a plain message informing the user that the form has been submitted.

(Previously I've been able to access the craft.request.getPost('name') but I don't think this works when using this plugin?

Thanks!

**Tags:** guest-entries


---

## 2 answers

### Answer by username_1 on 2016-05-23. Score: 2 | Accepted answer

You could append a query string on your redirect url that you can then query for in your template. I've used this to display different messages for a new post or an edited post.

{% set message = craft.request.getQuery( 'message' ) %}

{% if message|length and message == 'photo-added' %}
  Thank's for uploading your image
{% endif %}

To use fields from the saved entry you could use a plugin and watch for the entries.onSaveEntry event that will fire when using the Guest Entries plugin. 
craft()->on( 'entries.onSaveEntry', function( Event $event ){
  // Grab the entry from post request
  $entry = $event->params['entry'];

  // Add some conditionals so you only perform the redirect for the section you're posting to in the front end

  $name = $entry->getContent()->fieldName;

  // Render a template and pass the $name in
  //( not sure how to do this? )
});

> **Comments:**
> **username_0**: Thanks Luke. Would it be possible with the second approach to return to the same page and output a message there?  I guess all I want to do is say "Thanks for getting in touch". Would rather avoid query strings but if it's the easiest way...  
> **username_1**: Realised I missed out the name part of your question - updated my answer  
> **username_0**: Thanks so much Luke for your updated answer, I will give it a whirl!  
> **username_1**: Hang on, I've got the template render thing wrong  
> **username_2**: You're a machine, @LukePearce.  
> **username_0**: Thanks again Luke, I'd be interested in seeing about how to pass in the template but have opted for the far simpler query method. I'm guessing there is no way to query the forms submission natively then with saveEntries.  
> **username_3**: @LukePearce I don't think your "Render a template and pass the $name in" will actually work, because of the redirect that will take place following it. See my answer for an alternate.  

---

### Answer by username_3 on 2016-10-12. Score: 1

From what I can tell, Luke's answer wont actually work, because ultimately after the saveEntry event, GuestEntries will redirectToPostedUrl, which will lose any variables you have passed.
You options are explained here: Is it possible to setRouteVariables when redirecting after a successful form submission?
Example using SESSION:
// custom/CustomPlugin.php
craft()->on('guestEntries.onSuccess', function($event) {
    $entry = $event->params['entry'];
    craft()->httpSession->add('lastEntryId', $entry->id);
});

// custom/CustomVariable.php
public function getLastEntry()
{
    if (craft()->httpSession->get('lastEntryId'))
    {
        $entryId = craft()->httpSession->get('lastEntryId');
        $entry   = craft()->entries->getEntryById($entryId);

        craft()->httpSession->destroy('lastEntryId');
    }

    return $entry ?? null;
}

// In your success template
{% if lastEntry %}
    Review "{{ lastEntry.title }}" submission successful.
{% endif %}


---

