3 users online. Create an account or sign in to join them.Users
How do I prevent users from submitting their forms multiple times?
This is an open discussion with 33 replies, filed under Troubleshooting.
Search
The only way (I can think of) is to redirect the user to another (success-) page… This seems to be the de-facto 'best-practice' (but has issues). Otherwise a reload will re-submit the form.
Alternatively you could hijack the default form-submission with JS.
You can also redirect the user to the same page; they won't notice it but afterwards reloading the form won't have any effect as all POST data is removed by the redirect.
OK, thanks. But how can this redirect thing be done?
Add <input type="hidden" name="redirect" value="PATH HERE" /> to you form.
You can just change the form's action attribute or manage it in your form (or JS) logic/event.
Update or, indeed, add the redirect hidden input ;)
Remember that, when you redirect after a form submission, you'll lose your POST information: you will not be able to e.g. personalize a 'thank-you' message based on the submitted info: e.g. "Thanks Dave, we will send you more info on FOO shortly…"
You can work around this by e.g. adding those value to the url (/thanks/?name=Dave&info=FOO) for example...
Doo, that sounds a bit tricky.
The redirect seems easy to do but can I still display a confirmation message as well?
I normally use Symphony's @result attribute to display either an error or a success message.
I really need this functionality here to confirm to the user if s/he has booked the event or not.
That's the issue with a redirect: POST values are lost so you will not have an <event> in your XML.
Normally you would not redirect when there was a validation error: in that case you would simply show the form again: complete with validation error messages.
So, you can assume that a redirect == a successful form submission.
The redirect seems easy to do but can I still display a confirmation message as well?
Page = /contact/
Param = action
Redirect = /contact/thankyou/
<xsl:if test="$action = 'thankyou'">
<p>Message here</p>
</xsl:if>
OK, so that means I will have to create another page containing the confirmation message Your event has been booked. and redirect to it?
Edit: OK, I was too fast.
OK, so that means I will have to create another page containing the confirmation message
Or add message as a URL parameter on the end of your contact page, so you can load the contact page with /thankyou/ and grab it with $message in the page and show the message. Saves creating a new page.
Thanks. Actually, I found a much easier way.
I just built my form in a way that won't display any input fields once the form has been successfully submitted:
<form method="post" action="" enctype="multipart/form-data">
<fieldset>
<xsl:choose>
<xsl:when test="events/send-message[@result = 'success']">
<p class="success">Thanks.</p>
</xsl:when>
<xsl:otherwise>
<xsl:if test="events/send-message[@result = 'error']">
<p class="error">There was an error.</p>
</xsl:if>
all the input fields...
</xsl:otherwise>
</xsl:choose>
</fieldset>
</form>
This really works great. I really wonder why it's not implemented in the Symphony default installation.
In the meantime I found out that I was probably wrong to accuse my users of deliberately sending their messages multiple times.
I think what happens is that when a user returns to the contact page later on (by using the back button in his browser) a pop-up will ask him whether to send the form data again or not. At least this happened to me once today (in Safari 5.1.2) as I was sending some test mails.
This would also explain why some users have sent the same message 9 (!) times. Is there any way to prevent this from happening?
In the meantime I found out that I was probably wrong to accuse my users of deliberately sending their messages multiple times.
Don't worry, they blame you/us for lots of stuff everyday ;)
For me using the "Can Of Spam"-Extension prevents forms from being submitted twice. (In fact the form data still is submitted twice, but detected as Spam the second time because the hash has been renewed server-side while the browser resubmits the old hash on page reload).
OK, will give this a try.
It's strange that forms get submitted multiple times, though. It happened to me a couple of times before with other Symphony sites. Is this something specific to Symphony?
E.g. it never happened to me that a form got submitted twice in Expression Engine...
Is this something specific to Symphony
It's common with any website, that if you post the form to the same page, the user can refresh it and re-send the POST again. The vast majority of sites, probably default Expression Engine behaviour included, will redirect to a new URL.
So should I add a redirect to my forms then to prevent multiple submissions?
Yep that's what we've been suggesting. You could redirect to a new page, or redirect to the same page but pass a URL param (to save creating a new page just for a Thank You message).
So should I add a redirect to my forms then to prevent multiple submissions?
Yes, I use the redirect with param method as well.
Create an account or sign in to comment.
Hello,
Is there any way to prevent users from submitting a contact form multiple times?
I built a very simple booking system for a client but users tend to submit their booking twice or thrice. Today a new record was hit when a user submitted his form six times!
The form I am using is basically the same as in the default Symphony installation.
I wonder if there's any way to disable the input fields once a form has been submitted successfully?