4

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 %}
2
  • What template error does it throw? Commented Jul 11, 2014 at 21:04
  • Variable "test" does not exist—I'll add it to the question if I can.
    – mjr
    Commented Jul 11, 2014 at 21:12

2 Answers 2

9

I think you want this:

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

Pass a string to getPost()

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

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 %}

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

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