In this tutorial I’ll show you how to redirect a url after form submission using php. What can be achieved by doing so..?? As it is one of the basic requirements of website. Through redirection you can actually divert your user after submitting form to land to particular page of your choice in order to perform certain actions. Redirection benefits you in many ways.
Now in PHP, redirection is done by using header() function as it is considered to be the fastest method to redirect traffic from one web page to another. The main advantage of this method is that it can navigate from one location to another without the user having to click on a link or button.
Watch the live demo or download code from the link given below
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 user fills all fields and clicks on submit button in redirect_form.php, this PHP code will executes and redirects to url mentioned in the code.
<?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:https://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
}
Conclusion:
This was all about php redirecting using header() function. Hope you liked it. Keep reading our other blog posts. 🙂
79 Replies to “PHP: Redirect To URL After Form Submission”
How can I get this to happen through a form in an iframe for the parent page?
Dear Sir,
I have a form on my website. I am running database saving code on same page where my form is exist when i use header to redirect its show header is already set. code is running well on my localhost but its not work when i upload it plz help me if you can because i consume a lot of time to resolve it
Hi there to every one, as I am truly eager of reading
this website’s post to be updated daily. It carries fastidious material.
You ought to be a part of a contest for one of the best websites on the net.
I will recommend this blog!
I always spent my half an hour to read this webpage’s
articles or reviews every day along with a cup of coffee.
Thanks for your personal marvelous posting! I actually enjoyed reading it,
you may be a great author.I will ensure that I bookmark your blog and definitely will come back from now on. I want to encourage you to definitely continue your great job, have
a nice evening!
Can I simply just say what a comfort to discover someone that truly understands
what they’re talking about on the internet. You actually know how to bring a problem to light and make it important.
More and more people really need to look at this and understand this
side of your story. It’s surprising you’re not
more popular given that you certainly possess the gift.
Thank You for posting this, it’s much appreciated.
Pleased with your response….!
Keep reading our other blog posts for getting more coding tricks….
Regards,
FormGet Team
You ought to take part in a contest for one of the best sites
online. I’m going to recommend this website!
Heartiest Thanks for such a wonderful appreciation…!
Hi there, yup this post is in fact pleasant and I have learned lot of things from it
about blogging. thanks.
Hello Altblue hosting,
That sounds really great ! Keep reading our other blog posts for getting more coding tricks.
Regards,
FormGet Team
I’d like to find out more? I’d want to find out more details.
There are numerous blogs available here , you can search for what you need to know.
I am sure you will be benefited with it.
Thanks & Regards,
FormGet Team.
this website is very use ful…i learned lots of tricks..thanks for guide..
Hi, yeah this paragraph is really good and I have learned lot of things from it regarding blogging.
thanks.
Your response is greatly appreciated !
Thanks & Regards,
FormGet Team.
Spot on with thjis write-up, I truly believe
this web site needs a great ddal more attention. I’llprobably
be back again to see more, thanks ffor the
information!
Hello BOE,
That sounds really great ! Keep reading our other blog posts for getting more coding tricks.
Regards,
FormGet Team
What i do not understood is in fact how you are not actually much
more neatly-favored than you might be now. You’re very intelligent.
You recognize therefore significantly in terms of this subject, produced me individually imagine it
from a lot of varied angles. Its like men and women are not fascinated unless
it is something to do with Woman gaga! Your individual stuffs outstanding.
At all times take care of it up!
If you are going for most excellent contents
like I do, simply go to see this website every day for
the reason that it provides quality contents, thanks
Hello Obat,
Thank you so much for such a kind appreciation.
Keep reading our other blog posts for more knowledge and coding tricks.
Regards,
Obat.
Hello to all, how is the whole thing, I think every one is getting more from
this website, and your views are nice in support of
new visitors.
May I just say what a relief to uncover a person that truly knows what
they’re discussing over the internet. You actually realize how
to bring a problem to light and make it important.
More and more people need to read this and understand
this side of your story. I was surprised that you’re not more popular since
you most certainly have the gift.
Hello Jasa,
That sounds really great ! Keep reading our other blog posts for getting more coding tricks.
Catch up new posts from here
Regards,
FormGet Team
Hi there, this weekend is good designed for me, because this occasion i am reading this impressive educational paragraph here
at my house.
I’ve been browsing on-line greater than three hours lately, but I by no means found
any interesting article like yours. It’s pretty worth enough for me.
Personally, if all webmasters and bloggeres made good content as you did,
thhe web can be much more useful than ever before.
Hi, its pleasant paragraph on the topic of media print,
we all be familiar with media is a wonderful source
of data.
Yes! Finally something about google penguin.
Spot on with this write-up, I absolutely believe this
amazing site needs a lot more attention. I’ll probably be returning
to read through more, thanks for the advice!
Works Perfect..
Heya i’m for the first time here. I came across this board and I to find It truly helpful
& it helped me out a lot. I’m hoping to give something again and help others like you aided me.
Great post. I was checking constantly this weblog and I’m impressed!
Very useful information particularly the closing section :
) I deal with such info much. I was looking for this certain info
for a very long time. Thanks and best of luck.
Hi there mates, nice article and nice arguments commented at this place, I am genuinely enjoying by these.
Good article. I’m facing some of these issues as well..
Hello, this weekend is pleasant designed for me, because this moment i am reading this wonderful informative post
here at my residence.
This page really has all of the information I wanted concerning this subject
and didn’t know who to ask.
Great post of something very useful. PHP form action with redirection is something any website should practice for engaging their audience, thank you again!
Great post but I was wondering if you could write a litte more on this topic?
I’d be very grateful if you could elaborate a little bit more.
Many thanks!
Just wish to say your article is as surprising. The clearness in your post
is just great and i could assume you’re an expert on this subject.
Fine with your permission let me to grab your RSS feed to keep up
to date with forthcoming post. Thanks a million and please keep up the gratifying work.
I couldn’t refrain from commenting. Perfectly written!
I’d like to find out more? I’d want to find out more details.
Content is king, and real content like this hard to find now days.
Hey Neeraj!
Where does the form data get stored?
Is a tactic to just redirect or does it get stored somewhere?
I’m observing your email stuff and almost ready to make a decision.
I’m starting CPA marketing.
Your input will help greatly.
Thank you!
Ethan
It’s just a redirect stuff in this example we are not storing data any where.
Thanks! Appreciate it.
Thanks for sharing such a good idea, post is pleasant, thats why i have
read it completely
Really love your site and the post as well to read for the best of the information about the topic you chose to write keep
up the good work and yes im going to subscribe to your website for more such amazing
articles….Cheers!
What’s up, its pleasant article concerning media print, we
all know media is a wonderful source of data.
Appreciation to my father who shared with me about this blog, this weblog is genuinely remarkable.
I pay a quick visit each day a few web sites
and information sites to read content, but this blog gives
feature based posts.
I loved as much as you’ll receive carried out right
here. The sketch is tasteful, your authored subject matter stylish.
nonetheless, you command get got an impatience over
that you wish be delivering the following. unwell unquestionably come further formerly again since
exactly the same nearly a lot often inside case you shield this
increase.
If some one wishes expert view about blogging and site-building afterward i advise him/her to pay a quick visit this webpage, Keep up the nice work.
The structure of your text enable them to that particular.
Well, you can start by selecting the best way to capture
the attention of prospective customers. In conclusion, you have to target certain keywords.
Can you tell us more about this? I’d care to find out
more details.
Can you tell us more about this? I’d love to find out more
details.
Love the content, we shared it with our Facebook page too.
Do you have anything else that goes this in deatail
about PHP Redirect to URL After Form Submission | FormGet ?
Just want to say your article is as astonishing.
The clearness in your put up is simply spectacular and i can assume you are knowledgeable in this subject.
Fine together with your permission let me to take hold of your RSS feed to stay updated with
imminent post. Thank you a million and please carry on the enjoyable
work.
I’m gone to tell my little brother, that he should also visit
this weblog on regular basis to obtain updated from most up-to-date news update.
It’s really very complicated in this busy life to listen news on TV,
so I only use internet for that reason, and obtain the latest news.
Very good post! We are linking to this particularly great article on our site.
Keep up the great writing.
Attractive section of content. I just stumbled upon your website and in accession capital
to assert that I get in fact enjoyed account your blog posts.
Anyway I will be subscribing to your augment and even I achievement you access consistently rapidly.
hello!,I really like your writing very a lot! share we be in contact extra approximately your
post on AOL? I need an expert in this area to unravel my problem.
Maybe that’s you! Having a look forward to see you.
Quality articles or reviews is the key to be a focus for the visitors to pay a quick visit the site, that’s what this web page is providing.
Hi to every body, it’s my first go to see of this blog; this web site contains remarkable and truly excellent stuff in support
of visitors.
Thank you for every other wonderful article.
Where else could anybody get that kind of info in such a perfect manner
of writing? I’ve a presentation subsequent week, and I’m
at the look for such info.
I got this web site from my buddy who shared with me regarding
this web page and now this time I am visiting this website
and reading very informative posts here.
Very good article! We will be linking to this great article on our site.
Keep up the good writing.
I have read so many articles regarding the blogger
lovers except this article is in fact a good piece of writing, keep it up.
Oh my goodness! Impressive article dude! Thanks, However I am having problems with your RSS.
I don’t understand the reason why I cannot join it.
Is there anybody else getting the same RSS issues? Anybody who knows the solution will you kindly respond?
Thanx!!
Some people are perfect at writing articles.
Pick the most appropriate individuals. Make certain that your posts are relevant and timely.
Marketing promotions campaigns to use small sentences and
easy language.
There is definately a lot to learn about this issue. I like all the points you have
made.
I relish, cause I found just what I was having a look for.
You’ve ended my four day lengthy hunt! God Bless you man. Have a great day.
Bye
I’m impressed, I have to admit. Seldom do I come across a blog that’s both equally
educative and engaging, and let me tell you, you have hit the nail on the head.
The issue is something too few folks are speaking intelligently about.
I am very happy I stumbled across this during my hunt for something relating to this.
For most recent news you have to visit the web and on the web
I found this site as a best website for most up-to-date updates.