Forum Moderators: coopster
Also, I wrote a JavaScript function to disbable all form fields after submittal. But if I do something like this...
document.form.submitButton = disabled;
document.form.submit();
IE will disable the submit button if I don't submit it. But if I do submit it, it enables it again. And if you click the back button, it's enabled. It works fine in Opera. Any clues?
Any other solutions?
- Include a randomly generated token in a hidden field on the form. I use a date-timestamp + sessionid + a few additional random characters. You don't need to keep track of the token at this point.
- When the form is submitted, the server checks the submitted token against a list of already-used tokens.
- If the token is found, then don't process the submitted form.
- If the token isn't found, then add it to the list and continue processing the form data.
The token list is specific to the user session.
One more question... can i do a permanent redirect after displaying a page for a certain amount of time?
Since I viewed the source of the page on the redirect page here, I guess a <META http-equiv="refresh"> works nicely.
Is there a way to make the submit button disabled and with a different value when you go Back to that page in IE?
[edited by: chadmg at 3:17 pm (utc) on June 2, 2004]
But I guess it depends what you're trying to prevent. If you just want to avoid people pressing "Submit" multiple times while the form is being processed, there are nice ways to do it with javascript; set the "disabled" property on the button and change its value to "Please Wait..." That's enough user feedback to alert people that the button has been pressed and they don't have to keep hammering on it like those buttons that trigger the "walk" signal at a busy intersection.
However if you have a contest entry form or a registration form you don't want people to submit multiple times, then you should do a SELECT to see if the data already exists before INSERTing the new record.
In some cases, if the SELECT finds a matching entry, you want to do an UPDATE instead of an INSERT. That's a nice method that will apply to thousands of situations. I call it a "SELECT?UPDATE:INSERT" strategy. Once you've created one form that uses that strategy, you'll find thousands of other uses for it.
Choose the fields that identify a distinct entry - sometimes these are combinations of names, e-mail addresses, zip codes, etc.
Some people like to simplify this using a hash or token (though whether or not it is indeed simpler is arguable). Create a hash of your distinct fields and store it along with the record. for instance:
$hash=MD5($name.$email.$ticketnum);
You'll store that hash in the database as 'hash', and it will be your "token" which identifies that data.
To see if the entry has already been submitted, do this:
$query="SELECT hash FROM table WHERE hash='".$hash."'
$result=mysql_query($query);
if (mysql_num_rows($result)){
// entry found.
// echo a message telling the user
// not to submit more than once.
}else{
// insert the new data, and don't forget the hash
// echo a "thank you" message to the user.
}
Good luck!
let me elaborate on my dilemna with javascript in IE. this does not seem to work in IE...
<form name="form1" method="post" action="?">
<input name="cont" value="Submit" type="submit" onclick="document.form1.cont.value='Please wait...';document.form1.cont.disabled = true; document.form1.submit();">
</form>
It works when you remove the submit. But after the form is submitted the onclick effects magically disappear. :( Any ideas on how to keep them around? Should I post this question in the jscript forum?