There are two methods GET and POST.
In PHP, forms can be submitted using various methods. The common methods are:
- GET method: This method sends the form data appended to the URL in a query string. It is suitable for transferring small amounts of data. In PHP, you can access the submitted data using the
$_GET
superglobal array.
html
<form action="submit.php" method="GET">
<!-- Form fields go here -->
<input type="submit" value="Submit">
</form>
- POST method: This method sends the form data in the body of the HTTP request. It is suitable for transferring large amounts of data and sensitive information. In PHP, you can access the submitted data using the
$_POST
superglobal array.
html
<form action="submit.php" method="POST">
<!-- Form fields go here -->
<input type="submit" value="Submit">
</form>
- Using JavaScript: You can also submit a form using JavaScript by calling the
submit()
method of the form element.
html
<form id="myForm">
<!-- Form fields go here -->
<input type="submit" value="Submit" onclick="submitForm()">
</form>
<script>
function submitForm() {
document.getElementById("myForm").submit();
}
</script>
These are the primary methods for submitting forms in PHP. The choice between GET and POST depends on the nature of the data being submitted and security considerations.