document.forms["myform"].onsubmit=function(){
console.log('submitting');
return false;
};
<html>
<head>
</head>
<body>
<form id="myform" name="myform">
</form>
<input form="myform" type="text" name="username">
<input form="myform" type="submit" name="submit">
</body>
</html>
If for some reason the OP prefers to place the inputs outside the form that's permissable with HTML5 and should allow the form submission to still occur as long as each input bears a form attribute.
When the form is submitted, you need PHP to check if the form submission is valid by writing code like the following:
<?php
if ( isset( $_POST["submit"] ) ) {
// process the form submission
}
OR:
if ( isset( $_GET["submit"] ) ) {
// process the form submission
}