<p>Add a <a href="https://github.com/aelvan/Preparse-Field-Craft" rel="nofollow">Preparse field</a> to the entry type you're posting to and make it generate a random string on entry save.
Then make the Guest Entries plugin redirect to a URL with that Preparse field's value in the query string.</p>

<p><code>&lt;input type="hidden" name="redirect" value="success?id={id}&amp;key={preparseField}"&gt;</code></p>

<p>You should now be able to get that entry model in your template and test against that Preparse field's value.</p>

<pre><code>{% set query = craft.request.getQuery() %}
{% set entry = craft.entries.id(query.id).preparseField(query.preparseField).first() %}

{% if not entry %}
    {% exit 404 %}
{% endif %}
</code></pre>

CC BY-SA 3.0
2016-04-02T12:04:39.970Z
Hi @carlcs So basically this plugin pass a value set in preparse field setting page in CP to some model in front end only on entry save event? I've set some value with several characters to shuffle like this `{% set chars = '0123456789'|split('') %} {% set string = shuffle(chars)|join %} {{ string|slice(0, 5) }}` and saved it as preparse field with handle `secterKey`. On the front end everything is according to your answer in code except I changed `key={secretKey}` and `.preparseField(query.secretKey)`. I got error message that key `secretKey` doesn't exist.
Dominik Krulak
CC BY-SA 3.0
2016-04-02T12:08:39.790Z
I'm not even sure I proceed correctly because on entry form my URI looks like this `...success?id=123&key=`. I assume the string variable I set doesn't get passed to element model. Or I don't understand How it works. On plugin setting page both options are enabled. I think that doesn't effect it.
Dominik Krulak
CC BY-SA 3.0
2016-04-04T12:11:30.820Z
@dominik yeah, I forgot that the plugin saves Preparse fields after the element itself is saved. Have a look at my forked version of the plugin that has a "Parse before save" option added. https://github.com/carlcs/craft-preparsefield
carlcs
CC BY-SA 3.0
2016-04-04T19:48:07.163Z
Thank you for your effort to update the plugin. That worked well. Upon successful form submission my URI looked like this `?id=422&key=097306`  but template got error with following message: **Key "secretKey" for array with keys "p, id, key" does not exist**. So I though I'm not accessing the actual string value but preparseField itself. So I ended up with `(query.string)` whereas it got passed through this error message but have encountered on another one. It can't access an attribute  `("attribute")` on a string variable `("422")` which is our `entry.id`. It seems to be a minor mistake
Dominik Krulak
CC BY-SA 3.0
2016-08-24T07:45:18.607Z
Hi @carlcs. Would it still work if we upload a file? The Preparse field seems to be break generating a `key` string (_remain blank_) on before entry save when a file is attached to form. I think it connects's to [this issue](https://github.com/aelvan/Preparse-Field-Craft/issues/9).
Dominik Krulak
CC BY-SA 3.0
2016-08-24T16:30:45.913Z
@dominik hmm.. so you are no longer using that fork of mine and updated to the latest Preparse plugin, and you have the "parse before save" option enabled in your field settings? Is this right?
carlcs
CC BY-SA 3.0
2016-08-25T06:02:19.133Z
Yes @carlcs you're correct at all. I had to upgrade because there was some issue with PHP 5.3. And I didn't realise that I had your fork running up until your answer. I think during upgrade files were just merged together as "parse before save" option still live. This option isn't by default If I remember that. So I assume your code hasn't been overwritten when upgraded.
Dominik Krulak
CC BY-SA 3.0
2016-08-25T06:07:38.077Z
Alright so it's working again?
carlcs
CC BY-SA 3.0
2016-08-25T06:14:22.387Z
It works as always do except when a file is sent over the form. A random string isn't generated in this case. It's get generated when I resave entry from back end.
Dominik Krulak
CC BY-SA 3.0
2016-03-31T22:56:35.050Z
2016-03-31T22:56:35.050Z
carlcs
<p>I have redirect to a web page upon successful form submission using guest plugin. The redirected page is in announcement tone so I'd like to prevent it from direct access with exception that comes from form submission.</p>

<p>Is there something Craft can do?</p>

<config>
Prevent direct access to a web page except redirect
# Prevent direct access to a web page except redirect

(Asked by: username_0 on 2016-03-31)

I have redirect to a web page upon successful form submission using guest plugin. The redirected page is in announcement tone so I'd like to prevent it from direct access with exception that comes from form submission.

Is there something Craft can do?

**Tags:** config

---

## 1 answers

### Answer by username_1 on 2016-03-31. Score: 3 | Accepted answer

Add a Preparse field to the entry type you're posting to and make it generate a random string on entry save.
Then make the Guest Entries plugin redirect to a URL with that Preparse field's value in the query string.

You should now be able to get that entry model in your template and test against that Preparse field's value.
{% set query = craft.request.getQuery() %}
{% set entry = craft.entries.id(query.id).preparseField(query.preparseField).first() %}

{% if not entry %}
    {% exit 404 %}
{% endif %}

> **Comments:**
> **username_0**: Hi @carlcs So basically this plugin pass a value set in preparse field setting page in CP to some model in front end only on entry save event? I've set some value with several characters to shuffle like this `{% set chars = '0123456789'|split('') %} {% set string = shuffle(chars)|join %} {{ string|slice(0, 5) }}` and saved it as preparse field with handle `secterKey`. On the front end everything is according to your answer in code except I changed `key={secretKey}` and `.preparseField(query.secretKey)`. I got error message that key `secretKey` doesn't exist.  
> **username_0**: I'm not even sure I proceed correctly because on entry form my URI looks like this `...success?id=123&key=`. I assume the string variable I set doesn't get passed to element model. Or I don't understand How it works. On plugin setting page both options are enabled. I think that doesn't effect it.  
> **username_1**: @dominik yeah, I forgot that the plugin saves Preparse fields after the element itself is saved. Have a look at my forked version of the plugin that has a "Parse before save" option added. https://github.com/carlcs/craft-preparsefield  
> **username_0**: Thank you for your effort to update the plugin. That worked well. Upon successful form submission my URI looked like this `?id=422&key=097306`  but template got error with following message: **Key "secretKey" for array with keys "p, id, key" does not exist**. So I though I'm not accessing the actual string value but preparseField itself. So I ended up with `(query.string)` whereas it got passed through this error message but have encountered on another one. It can't access an attribute  `("attribute")` on a string variable `("422")` which is our `entry.id`. It seems to be a minor mistake  
> **username_0**: Hi @carlcs. Would it still work if we upload a file? The Preparse field seems to be break generating a `key` string (_remain blank_) on before entry save when a file is attached to form. I think it connects's to [this issue](https://github.com/aelvan/Preparse-Field-Craft/issues/9).  
> **username_1**: @dominik hmm.. so you are no longer using that fork of mine and updated to the latest Preparse plugin, and you have the "parse before save" option enabled in your field settings? Is this right?  
> **username_0**: Yes @carlcs you're correct at all. I had to upgrade because there was some issue with PHP 5.3. And I didn't realise that I had your fork running up until your answer. I think during upgrade files were just merged together as "parse before save" option still live. This option isn't by default If I remember that. So I assume your code hasn't been overwritten when upgraded.  
> **username_1**: Alright so it's working again?  
> **username_0**: It works as always do except when a file is sent over the form. A random string isn't generated in this case. It's get generated when I resave entry from back end.  

---

