5

On a real estate website I'm working on I have a Contact Us form on the Property Details page where the user can click the Contact Us button, which will load the form in a modal dialog, an iframe loading the contact us form, fill in some details and send it off.

Once the form has been processed server side I have to emit JavaScript code from the server that calls the dialog close method and then redirects the user to a thank you page (If I did a simple redirect on the server the iframe would get the thank you page which I don't want).

The problem is in Chrome where if you hit the Browser's back button the contact form is quietly resubmitted.

Note: IE and Firefox don't have this issue at all.

I found the following links useful, but not the answer to my problem:

We've tried various techniques to circumvent the issue in Chrome like hidden fields, insured cache is turned off, destroy the iframe before redirecting to the thank you page. Nothing it keeps resubmitting the form without even asking if you want to resubmit (not that it should be resubmitting at all)

Community
  • 1
  • 1
Jacques
  • 6,062
  • 7
  • 37
  • 94
  • If it's a browser bug, there's nothing you can do to fix the problem. My suggestion would be, look to use a single page application architecture, even for this small section, so there is no back button, or at least not one that re-loads the parent document. – Alex Oct 16 '15 at 06:50
  • You are controlling the Iframe where you have contact us form? Or it's external? – SilentTremor Oct 16 '15 at 08:45
  • @SilentTremor it's our form so we have full control. Why what are you thinking? – Jacques Oct 16 '15 at 12:42
  • Add to posted object an empty hidden field, field that will get populated when you press submit button if you have submit button on frame form, if you can do that I can help you with catching the substitution and post from javascript. – SilentTremor Oct 16 '15 at 13:06
  • Having the info if button was pressed on model hidden property, real click, in classic asp.net you could get the event source (form has 2 butttons) – SilentTremor Oct 16 '15 at 13:09

1 Answers1

0

Just come across this issue, what I'm thinking of doing is including some sort of one-time token (i.e. GUID) in the form, which if we re-detect on the server we can ignore the form post. Possibly use session state on the server to keep track - much like a Rails authenticity token

Community
  • 1
  • 1
Duncan Smart
  • 27,805
  • 8
  • 60
  • 69