Forum Moderators: coopster

Message Too Old, No Replies

On submit form, difference clicking submit or hitting enter?

         

bobnew32

4:30 pm on Oct 30, 2004 (gmt 0)

10+ Year Member



I know this has happened to me in the past and I have read it happened to others. But on some forms that you are "submitting", hitting the actual enter button is supposed to submit it, but gets an error.....? The only way for the form to actually go through 100% is clicking the submit button with your mouse. I put this here b/c all my forms are handled by php in the end, and was wondering if anyone can offer insight to this?

JamesRock

6:29 pm on Oct 30, 2004 (gmt 0)

10+ Year Member



Well I know that when you press enter it submits the currently active form. So potentially if you pressed enter and there was more than one form on the page, perhaps the wrong form is being submitted?

As far as I know form submissing is no different if it is done from clicking the submit button, pressing enter or using javascript.

The only thing I can think of is, sometimes people use the value of the submit button as a check to see which button was pressed (if there are multiple submit buttons), so by pressing enter it may submit the form but not set the value. For example:


<input type="submit" name="myform" value="Submit" />

You might have PHP code like:


<?php
if ($_POST["myform"] == "Submit") {
//process myform here
}
?>

However I believe if you press enter its the same as pressing the enter button anyway. Its a weird one, perhaps more details will help us solve your problem?

dcrombie

10:45 am on Oct 31, 2004 (gmt 0)



It probably comes down to JavaScript. The proper way to validate/submit forms is:

<FORM ... onSubmit="return validate(this);">

where 'validate()' is a JS function that returns a boolean value. This method will work if the submit button is pressed OR the user hits Enter.

The way NOT to do it is:

<INPUT type="button" ... onClick="validate(this.form);">

Where 'validate()' is a JS function that calls 'form.submit()'. If you don't click the button then the form won't be validated/submitted.

;)