I have a form that POSTs to a 3rd-party service for validation and information capture. In the 3rd-party back end, you can specify a URL for errors, and one option is “referring URL”.
That’s seemingly perfect. User POSTs an invalid form, and the page they are on “reloads” (not really, but that’s the impression) with error messages taken from a query string that looks like this:
http://somesite.com/?errorMessages=some%20message~~~some%20other%20message~~~etc
I parse out the separate error messages and push them into a DIV that advises the user what has gone wrong. So far so good.
However, the user continues to screw up the form, and when they POST again, the referrer is now the entire URL including the error messages. The server replies with the original error messages (it’s the referrer, after all!) as well as any remaining issues:
http://somesite.com/?errorMessages=some%20message~~~some%20other%20message~~~etc&errorMessages=new%20message~~~another%20new%20message~~~etc
You can see the issue(s), but to be clear:
- The form is long enough to begin with; these unchecked appends eventually cause the query string to exceed browser limitations and you get errors.
- The parse algorithm isn’t reporting back only the latest problems. It’s still reporting the original problems, too.
phew
That’s a long backstory for a simple question:
In the submit event, is there a way to clear the query string from the referring URL using JavaScript? I don’t want to do any referrer spoofing or avoid any legitimate security concerns, I just want to be able to send the “true” referring page minus the query string.
I’m already using jQuery, so any answers are free to use it as well.
Here is one way to do it: