PHP - FORM submit - ENTER vs. MOUSECLICK

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
hobro78
Forum Newbie
Posts: 2
Joined: Thu Apr 17, 2003 5:34 am

PHP - FORM submit - ENTER vs. MOUSECLICK

Post 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
User avatar
twigletmac
Her Royal Site Adminness
Posts: 5371
Joined: Tue Apr 23, 2002 2:21 am
Location: Essex, UK

Post 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
hobro78
Forum Newbie
Posts: 2
Joined: Thu Apr 17, 2003 5:34 am

Post by hobro78 »

You're right ! It's just an IE problem ! Thanks for your advice !!!

HoBro
Post Reply