How to redirect to another page after submitting a form in php.

In this tutorial, I’ll show you how to use URL redirection PHP form submission. What can be achieved by doing so ..? Because it is one of the basic requirements of the site. You can actually land in the form submitted by redirection to a specific page of your choice, in order to perform specific operations after the transfer, your users. Redirect benefit you in many ways.

Now, in PHP, the redirect by using header () function, because it is considered to be redirected from one page to another traffic the fastest way to completion. The main advantage of this method is that it can navigate from one location to another without the user clicking a link or button.

PHP File: redirect_form.php

This file consists of html form with four fields and a submit button.

 

<!DOCTYPE html>
<html>
<head>
<title>Redirect Form To a Particular Page On Submit - Demo Preview</title>
<meta content="noindex, nofollow" name="robots">
<link href='css/redirect_form.css' rel='stylesheet' type='text/css'> <!--== Include CSS File Here ==-->
</head>
<body>

<div class="main">

<div class="first">

<h2>Redirect Form To a Particular Page On Submit using PHP</h2>


<form action="redirect_form.php" id="#form" method="post" name="#form">
<label>Name :</label>
<input id="name" name="name" placeholder='Your Name' type='text'>
<label>Email :</label>
<input id="email" name="email" placeholder='Valid Email Address' type='text'>
<label>Contact :</label>
<input id="contact" name="contact" placeholder='Contact' type='text'>
<label>Address:</label>
<input id="address" name="address" placeholder='Address' type='text' value="">
<input id='btn' name="submit" type='submit' value='Submit'>
<!---- Including PHP File Here ---->
<?php include "include/redirect.php"; ?>
</form>

</div>

</div>

</body>
</html>

PHP script: redirect.php
When you fill in the redirection of form.php fields and clicks the submit button, the PHP code will execute and redirect code into the URL mentioned.

<?php
if(isset($_POST['submit'])){
// Fetching variables of the form which travels in URL
$name = $_POST['name'];
$email = $_POST['email'];
$contact = $_POST['contact'];
$address = $_POST['address'];
if($name !=''&& $email !=''&& $contact !=''&& $address !='')
{
//  To redirect form on a particular page
header("Location:http://www.formget.com/app/");
}
else{
?><span><?php echo "Please fill all fields.....!!!!!!!!!!!!";?></span> <?php
}
}
?>

CSS File: redirect_form.css

For Styling HTML Elements.

@import "http://fonts.googleapis.com/css?family=Droid+Serif";
/* Above line is used for online google font */
h2 {
text-align:center
}
hr {
margin-bottom:-10px
}
span {
color:red;
margin-left:65px
}
div.main {
width:960px;
height:655px;
margin:50px auto;
font-family:'Droid Serif',serif
}
div.first {
width:380px;
height:570px;
float:left;
padding:15px 50px;
background:#f8f8ff;
box-shadow:0 0 10px gray;
margin-top:20px
}
input {
width:100%;
padding:8px;
margin-top:10px;
font-size:16px;
margin-bottom:25px;
box-shadow:0 0 5px;
border:none
}
#btn {
width:100%;
padding:8px;
margin-top:10px;
background-color:#474242;
cursor:pointer;
color:#fff;
border:2px solid #adadad;
font-size:18px;
font-weight:700;
font-family:'Droid Serif',serif;
margin-bottom:15px
}
#btn:hover {
background-color:#adadad;
border:2px solid #474242
}