Complete working code to prevent form submission on Enter/Return Key. It will submit the form when user click on the Submit button.
1.php file
<?php
/* Add your php code here if needed */
?>
<!-- form starts -->
<form action="2.php" method="post" id="regForm">
<input name="a" type="text" />
<input name="b" type="text" />
<input name="sub" type="submit" value="Submit" />
</form>
<!-- form ends-->
<!-- Insert the code below before </body> Tag -->
<script src="https://ajax.googleapis.com/ajax/libs/jquery/1.12.0/jquery.min.js"></script>
<script>
$('#regForm').on('keyup keypress', function(e) {
var keyCode = e.keyCode || e.which;
if (keyCode === 13) {
e.preventDefault();
return false;
}
});
</script>
2.php file
<?php
//Show the form data that was sent here
echo "<pre>"; var_dump($_POST);
die;
?>
To learn more about PHP, please see the following links
PHP with HTML - PHP 5 Tutorial - learn php