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?



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.

<input type="hidden" name="redirect" value="my-photos?message=photo-added">

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

{% if message|length and message == 'photo-added' %}
  <p>Thank's for uploading your image</p>
{% 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? )
  • 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... May 23 '16 at 16:54
  • Realised I missed out the name part of your question - updated my answer May 23 '16 at 16:58
  • Thanks so much Luke for your updated answer, I will give it a whirl! May 23 '16 at 17:00
  • Hang on, I've got the template render thing wrong May 23 '16 at 17:06
  • You're a machine, @LukePearce.
    – Brad Bell
    May 23 '16 at 17:35

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);


    return $entry ?? null;

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

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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