Page 1 of 1

PHP - FORM submit - ENTER vs. MOUSECLICK

Posted: Thu Apr 17, 2003 5:34 am
by hobro78
hi there!

i have a strange problem and maybe somebody can help me :

let's say I've a form ( with inputs, selects, submitbutton etc. ) which submits the data to the same physical file ( e.g. index.php ). when the user enters some data and submits the form, I check the $_REQUEST["submit"] variable for its value and if set, I work with the data. ( if ($_REQUEST["submit"]) { ... } ). And now the bug : when the user clicks ( with the mouse ) on the submitbutton everything works fine, but when the user just presses the enter ( or return) key, the form submits but the $_REQUEST["submit"] (submitbutton) variable is not set ( theres no javascript or anythign else - just a normal form ) ! does anybody have the same problem or - better - a solution ? Thanks in advance !

HoBro

Posted: Thu Apr 17, 2003 5:50 am
by twigletmac
It's a browser thing - some will register the submit button being clicked if enter is pressed others (I'm not totally sure but I think IE is the one) don't. One way to get around that is to pass a hidden variable in your form:

Code: Select all

<input type="hidden" name="action" value="post" />
and then when the form is submitted, check for that rather than the submit button:

Code: Select all

if (isset($_POST['action']) && $_POST['action'] == 'post') {
    // form has been submitted
} else {
    // form has not been submitted
}
Mac

Posted: Thu Apr 17, 2003 9:20 am
by hobro78
You're right ! It's just an IE problem ! Thanks for your advice !!!

HoBro