473,503 Members | 2,046 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

preventing accidental form submission

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
3 1731
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
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
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 thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

8
2305
by: CJM | last post by:
How do people go about preventing the user from submitting a form for a 2nd time? For example, the user submits a form, clicks on the back button, and the submits the form again. I have used...
2
7018
by: Andy Goldstein | last post by:
I have a table where all the TRs have an onClick handler registered. One (and only one) of the rows has 2 text input boxes, where each textbox has an onChange handler registered. Both the onClick...
8
4752
by: yawnmoth | last post by:
Say I have the following HTML: <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"> <html> <head> <title></title> </head> <body> <form action="">
12
2126
by: Mark Rae | last post by:
Hi, See the previous thread Request.Form abuse in this newsgroup... I'm looking for a simple and efficient way to prevent people hijacking the <formtags on my websites and using them to send...
6
11863
by: Oleg Konovalov | last post by:
Hi, I have a Java/JavaScript GUI application where I perform a lot of long DB operations , which takes 5-60 secs to perform. Sometimes user double-clicks the button or just gets impatient and...
1
2492
by: Homer | last post by:
Hi, I just got a requirement from my HR department to automate their form submission process and integrate it into the Intranet project that I had just completed Phase 1 of. Because of the...
2
1362
by: dwmartin18 | last post by:
I got it into my head the other day to develop my own little form validation library. More than anything I just wanted to try out of few things I’ve never done before like chainable methods -- think...
8
4331
Megalog
by: Megalog | last post by:
Hey guys.. my turn to ask a question: I'm having a weird issue with a form I've reworked. This form has a combo box, which when used is changing the recordsource of a subform. This subform has...
12
2094
by: MikeB | last post by:
I created a small website for a friend. On this website he has a contact page where people can send him email. When I wrote this page I checked some tutorial pages and they warned about certain...
0
7282
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
7342
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
1
6998
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
7464
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
5586
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...
0
4680
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and...
0
3171
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The...
0
3162
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
0
391
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.