By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
435,131 Members | 1,560 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 435,131 IT Pros & Developers. It's quick & easy.

preventing accidental form submission

P: n/a
I've been having trouble preventing users pressing Enter part way down
a form so the incomplete form gets submitted.

I came up with a possible solution - the code below seems to work in
both mozilla and MSIE - is this a good way to solve the problem? Is
there a better alternative? Have I done anything stupid?

My aim was to disable the normal submit process then use javascript to
submit which appears to bypass that and work...

Neither the normal submit button nor pressing Enter result in the form
being sent (so in a real world application one would use a button
rather than the normal submit field type).

<HTML><HEAD><TITLE></TITLE></HEAD><BODY >
<FORM ACTION="http://www.example.com/cgi-bin/myprogram.pl"
METHOD="POST" name="myform" onSubmit="return false;">
<input type="text" size="45" name="afield" value="a field" ><BR>
<INPUT type="reset" value="Reset">
<INPUT type="button" value="Submit (button)"
onClick="document.myform.submit();">
<INPUT type="submit" value="Submit (normal)" >
</FORM></BODY></HTML>
Jul 23 '05 #1
Share this Question
Share on Google+
3 Replies


P: n/a
On Mon, 27 Sep 2004 19:48:07 GMT,
<sh******************@spam.hairdresser.net> wrote:
I've been having trouble preventing users pressing Enter part way down a
form so the incomplete form gets submitted.

I came up with a possible solution - the code below seems to work in
both mozilla and MSIE - is this a good way to solve the problem? Is
there a better alternative? Have I done anything stupid?


All you should try to do is check the values on both client and server. If
the form seems incomplete, display it again filled with the submitted
values and tell the user to complete the form before sending it. The user,
having any sense, will see that pressing Enter at the time they did isn't
a good idea, and it should be last time they do it.

No need to confuse the issue with multiple buttons, some working and some
not. Some dependent on scripting and some not.

[snip]

Mike

--
Michael Winter
Replace ".invalid" with ".uk" to reply by e-mail.
Jul 23 '05 #2

P: n/a
On Mon, 27 Sep 2004 22:17:35 GMT, "Michael Winter"
<M.******@blueyonder.co.invalid> wrote:
On Mon, 27 Sep 2004 19:48:07 GMT,
<sh******************@spam.hairdresser.net> wrote:
I've been having trouble preventing users pressing Enter part way down a
form so the incomplete form gets submitted.

I came up with a possible solution - the code below seems to work in
both mozilla and MSIE - is this a good way to solve the problem? Is
there a better alternative? Have I done anything stupid?
All you should try to do is check the values on both client and server. If
the form seems incomplete, display it again filled with the submitted
values and tell the user to complete the form before sending it. The user,
having any sense, will see that pressing Enter at the time they did isn't
a good idea, and it should be last time they do it.


I agree that is a better approach *where practicable* however it makes
the assumption that all the fields are required to be completed, this
is not always the case and this is the shortcoming I am trying to
address.
No need to confuse the issue with multiple buttons, some working and some
not. Some dependent on scripting and some not.

The example had two submit buttons in order to demonstrate the
difference in their operation, a real-world implementation would not.

Jul 23 '05 #3

P: n/a
sh******************@spam.hairdresser.net wrote:
All you should try to do is check the values on both client and server. If
the form seems incomplete, display it again filled with the submitted
values and tell the user to complete the form before sending it. The user,
having any sense, will see that pressing Enter at the time they did isn't
a good idea, and it should be last time they do it.

I agree that is a better approach *where practicable* however it makes
the assumption that all the fields are required to be completed, this


Not at all. Mike is saying check the values on the client
to prevent a wasted trip to the server. If the user doesn't
have javascript enabled, you have to rely on server-side
validation and response.

His comment regarding "tell the user to complete the form
before sending it" is in the context of telling the user to
complete all mandatory fields, I don't think he means they
must complete every field necessarily. Hopefully you have
on-screen help and tips so that the user knows which fields
are mandatory and those that aren't and are guided as to
correct formats, etc.

Cheers, Rob.
Jul 23 '05 #4

This discussion thread is closed

Replies have been disabled for this discussion.