Krakow poland hotels - Debt Consolidation - Apartment Budapest - Loans - Debt Consolidation

PDA

View Full Version : Getting Enter from keyborad insetead of $_POST


babaMBA
Jul 16th 2007, 9:44 pm
I am using two forms on one .php page and both of them performing different functions.

I can get the submit of the button in the form by

if( $_post['btnSubmit'] )
{
do some thing
}

but in this case if user press enter button instead of clicking the submit button by mouse then the "do something " statments are not executed.

Plz help me that how can i solve my problem, I want my code to be executed by both click of mouse on submit button and the enter from keyboard.

Thx in Advance.

NoamBarz
Jul 16th 2007, 10:43 pm
If the user clicks "enter", the form submitted is the default form. If you have two forms on the page, that'll be a problem. How could you know which form the user meant to click?

You could solve the problem by giving each form submit button a different name. So you'd have:

<input type='submit' name='but1' value=' 1st form '>

and

<input type='submit' name='but2' value=' 2nd form '>

then, in your php, just use:

if($_POST["but1"]){
execute first form
}
else{
execute 2nd form
}

Still, if the user doesn't click on the submit button, how would you know which button he meant to click?

babaMBA
Jul 16th 2007, 11:15 pm
I did the same
if($_POST['btnSubmit'])
{
do something
}

but this works only with click on submit button and not with enter from keyboard.

is there anymethod that can read the enter from keyboard and "do something" executed.

srobona
Jul 16th 2007, 11:41 pm
Use 'get' method instead of 'post' in the form tag, so that the form will be submitted whether the user clicks the button or press enter. Also, you need to change the if($_POST["but1"]) to if($_GET["but1"])