File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
The moose likes HTML, CSS and JavaScript and the fly likes Submit Form / POST on page refresh Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Engineering » HTML, CSS and JavaScript
Bookmark "Submit Form / POST on page refresh" Watch "Submit Form / POST on page refresh" New topic

Submit Form / POST on page refresh

Sam Gardner
Ranch Hand

Joined: Jul 22, 2008
Posts: 48
Hey Guys -

I have a timed page that I need to use to submit a form upon the end of a specified time period.

The usage would be: User visits page, 90 seconds later all form data is submitted and user is redirected to next page.

The user is well aware that the page they are on is timed (its for a web-only experiment), so I'm not too worried about "unfriendly" browser behavior on this page.

Ideally, I'd like to avoid using JavaScript (some of our targeted users are using no-script for various reasons, but if its the only way, so be it), and would also like to avoid just passing variables through the URL (to cut down on the possibility of spoofing). It is easy enough to set a META refresh tag to do the redirecting, but at the end of the time period I need some way for the response header to be set as if the submit button was clicked, whether or not it actually was.

Thanks in advance for any thoughts you might have.
Jeanne Boyarsky
author & internet detective

Joined: May 26, 2003
Posts: 33102

I think you have to use JavaScript for this.

As far as the URL, you could use a POST to pass parameters. But that can be spoofed too. You really can't trust anything from the client absolutely.

[OCA 8 book] [Blog] [JavaRanch FAQ] [How To Ask Questions The Smart Way] [Book Promos]
Other Certs: SCEA Part 1, Part 2 & 3, Core Spring 3, TOGAF part 1 and part 2
Eric Pascarello

Joined: Nov 08, 2001
Posts: 15385
Well there is no way to submit the form other than the user clicking a button or calling it with JavaScript.



will be your friend

Andy Crane

Joined: Dec 30, 2008
Posts: 17
I agree with Eric. Well, agree may not be correct, as in, he's right, you're not going to submit that form unless you use javascript.

He's got the correct way to think about it as well. You're not refreshing the page on timeout, you're submitting the form on timeout.

You can provide a message for the noscript users letting them know that the page will not refresh and that they will need to click submit in order to submit the form.

The other users won't be impacted at all this way.

- andy c
"Pseudo code first. If you can pseudo code accurately, when you start writing code, you're just applying syntax to the pseudo code. It separates the two most complicated pieces of programming into manageable bites. You create your app's workflow without worrying about syntax. Then you code without worrying about your app's workflow."
I agree. Here's the link:
subject: Submit Form / POST on page refresh
It's not a secret anymore!