preventing accidental form submission

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • shortbackandsides.no@spam.hairdresser.net

    #1

    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><TI TLE></TITLE></HEAD><BODY >
    <FORM ACTION="http://www.example.com/cgi-bin/myprogram.pl"
    METHOD="POST" name="myform" onSubmit="retur n false;">
    <input type="text" size="45" name="afield" value="a field" ><BR>
    <INPUT type="reset" value="Reset">
    <INPUT type="button" value="Submit (button)"
    onClick="docume nt.myform.submi t();">
    <INPUT type="submit" value="Submit (normal)" >
    </FORM></BODY></HTML>
  • Michael Winter

    #2
    Re: preventing accidental form submission

    On Mon, 27 Sep 2004 19:48:07 GMT,
    <shortbackandsi des.no@spam.hai rdresser.net> wrote:
    [color=blue]
    > 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?[/color]

    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.

    Comment

    • shortbackandsides.no@spam.hairdresser.net

      #3
      Re: preventing accidental form submission

      On Mon, 27 Sep 2004 22:17:35 GMT, "Michael Winter"
      <M.Winter@bluey onder.co.invali d> wrote:
      [color=blue]
      >On Mon, 27 Sep 2004 19:48:07 GMT,
      ><shortbackands ides.no@spam.ha irdresser.net> wrote:
      >[color=green]
      >> 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?[/color]
      >
      >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.[/color]

      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.
      [color=blue]
      >No need to confuse the issue with multiple buttons, some working and some
      >not. Some dependent on scripting and some not.[/color]
      The example had two submit buttons in order to demonstrate the
      difference in their operation, a real-world implementation would not.

      Comment

      • RobG

        #4
        Re: preventing accidental form submission

        shortbackandsid es.no@spam.hair dresser.net wrote:
        [color=blue][color=green]
        >>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.[/color]
        >
        >
        > I agree that is a better approach *where practicable* however it makes
        > the assumption that all the fields are required to be completed, this[/color]

        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.

        Comment

        Working...