I'm working with the contact form plugin and would like to test for post data to see if the form was just submitted.

It seems this code always throws a template error.

Variable "test" does not exist

Is there a better way to do this?

{% set success = craft.request.getPost(test) %}
{% if success %}
    form was just submitted
{% endif %}
  • What template error does it throw? – Marion Newlevant Jul 11 '14 at 21:04
  • Variable "test" does not exist—I'll add it to the question if I can. – mjr Jul 11 '14 at 21:12

I think you want this:

{% set success = craft.request.getPost('test') %}
{% if success %}form was just submitted{% endif %}

Pass a string to getPost()

| improve this answer | |
  • Looks like my issue was I didn't add quotes around the name param passed to getPost. My bad, thanks! – mjr Jul 14 '14 at 13:54

If you just want to test if something is in POST, and don't care what it is, then this should work:

{% set success = craft.request.getPost() | length %}

{% if success %}
    form was just submitted
{% endif %}
| improve this answer | |

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.