How can you submit a form without a submit button?

You can use JavaScript submit() function to submit the form without explicitly clicking any submit button.

In PHP, forms are typically submitted using HTML <form> elements with a submit button. However, there are alternative ways to submit a form without a submit button using JavaScript. One common method is by triggering the form submission through JavaScript event handling.

Here’s an example using JavaScript to submit a form without a submit button:

html
<!DOCTYPE html>
<html>
<head>
<title>Submit Form Without Button</title>
</head>
<body>

<form id="myForm" action="submit.php" method="post">
<input type="text" name="username" placeholder="Enter Username">
<input type="password" name="password" placeholder="Enter Password">
<!-- No submit button here -->
</form>

<script>
// Get the form element
var form = document.getElementById('myForm');

// Function to submit the form
function submitForm() {
form.submit();
}

// Call the submitForm function when needed, for example, on page load
window.onload = function() {
submitForm();
};
</script>

</body>
</html>

In this example, the form is submitted automatically when the page loads using the submitForm() function triggered by the window.onload event. This way, you don’t need a submit button in the form. Instead, the form submission is handled programmatically through JavaScript.