shabi
answered Apr 26 '23 00:00
To submit an HTML form to an action PHP file, you need to set the action attribute of the form to the URL of the PHP file. Here is an example:
<!-- HTML form -->
<form method="post" action="process-form.php">
<label for="name">Name:</label>
<input type="text" name="name" id="name">
<label for="email">Email:</label>
<input type="email" name="email" id="email">
<input type="submit" value="Submit">
</form>
In this example, when the form is submitted, it will send a POST request to the process-form.php file. You can then use PHP code in the process-form.php file to handle the form submission and process the form data. Here is an example:
<?php
// process-form.php
if ($_SERVER['REQUEST_METHOD'] === 'POST') {
// Get the form data
$name = $_POST['name'];
$email = $_POST['email'];
// Do something with the form data
// ...
}
?>
In this example, the $_POST superglobal array is used to retrieve the form data. You can then process the form data as needed.