How can the PHP code be modified to ensure that after form submission, the form is completely cleared of all input data?
To ensure that the form is completely cleared of all input data after submission, you can use the header() function to redirect the user back to the same page after processing the form data. This will reload the page and clear any input data that was previously submitted.
<?php
if ($_SERVER["REQUEST_METHOD"] == "POST") {
// Process form data here
// Redirect to the same page to clear input data
header("Location: ".$_SERVER['PHP_SELF']);
exit();
}
?>
<!DOCTYPE html>
<html>
<head>
<title>Clear Form After Submission</title>
</head>
<body>
<form method="post" action="<?php echo $_SERVER['PHP_SELF']; ?>">
<!-- Form fields go here -->
<input type="text" name="name" placeholder="Name">
<input type="email" name="email" placeholder="Email">
<button type="submit">Submit</button>
</form>
</body>
</html>