Tags
Asked 2 years ago
9 Jun 2021
Views 246
pratik

pratik posted

PHP form submit

PHP form submit
ching

ching
answered Apr 26 '23 00:00

To submit an HTML form in PHP, you need to create an HTML form and set its action attribute to a PHP file that will handle the form submission. Here is an example of a simple form:



<!-- HTML form -->
<form method="post" action="submit.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, the form's method attribute is set to post, which means that the form data will be sent as an HTTP POST request. The action attribute is set to s ubmit.php, which is the PHP file that will handle the form submission.

In the submit.php file, you can use PHP code to retrieve the form data that was submitted. Here is an example of how to do this:

php
Copy code
<?php
// submit.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 using PHP code.




Post Answer