dezkit Posted August 30, 2008 Share Posted August 30, 2008 I have this script that i made: <?php $submit = $_POST["submit"]; $firstname = $_POST["firstname"]; $lastname = $_POST["lastname"]; if(isset($submit)){ if($submit == "Create"){ echo "$firstname $lastname has been created in the database."; } elseif($submit == "Delete"){ echo "$firstname $lastname has been cleared from the database."; } } else { ?> <form action="" method="post"> <table> <tr> <td>First name: <td><input type="text" name="firstname"> <tr> <td>Last name: <td><input type="text" name="lastname"> <tr> <td colspan=2> <input type="submit" name="submit" value="Create"> <input type="submit" name="submit" value="Delete"> <input type="reset" name="reset" value="Reset"> </table> </form> <?php } ?> and i was wondering if there is a way for that if people press enter, the form doesn't submit. Quote Link to comment Share on other sites More sharing options...
Barand Posted August 30, 2008 Share Posted August 30, 2008 This has to be javascript so moving to js forum. Pressing enter causes the default submit button to be clicked (in this case "create") so you can use mouse up to see if it really was clicked. <?php echo '<pre>', print_r($_POST, true), '</pre>'; ?> <html> <head> <meta name="generator" content="PhpED Version 4.5 (Build 4513)"> <title>sample</title> <meta name="author" content="barand"> <link rel="shortcut icon" href=""> <meta name="creation-date" content="08/30/2008"> <script type='text/javascript'> var buttonClicked = false; function checkButtonClicked() { return buttonClicked; } </script> </head> <body> <form action="" method="post" onsubmit='return checkButtonClicked()'> <table> <tr> <td>First name: <td><input type="text" name="firstname"> <tr> <td>Last name: <td><input type="text" name="lastname"> <tr> <td colspan=2> <input type="submit" name="btnsubmit" value="Create" onmouseup='buttonClicked=true'> <input type="submit" name="btnsubmit" value="Delete" onmouseup='buttonClicked=true'> <input type="reset" name="reset" value="Reset"> </table> </form> </body> </html> Quote Link to comment Share on other sites More sharing options...
dezkit Posted August 30, 2008 Author Share Posted August 30, 2008 Thanks so much! Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.