Is it advisable to use JavaScript for redirecting to a new page after submitting a form in PHP?
It is not advisable to use JavaScript for redirecting to a new page after submitting a form in PHP because it may not work if the user has JavaScript disabled. Instead, you can use PHP header() function to redirect the user to a new page after form submission.
<?php
if ($_SERVER["REQUEST_METHOD"] == "POST") {
// Process form data here
// Redirect to a new page after form submission
header("Location: newpage.php");
exit();
}
?>
<!DOCTYPE html>
<html>
<head>
<title>Form Submission</title>
</head>
<body>
<form method="post" action="<?php echo $_SERVER['PHP_SELF']; ?>">
<!-- Form fields here -->
<input type="submit" value="Submit">
</form>
</body>
</html>