Newbie-after form submission return to home page?

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
ducatigirl67
Forum Newbie
Posts: 22
Joined: Sun Sep 13, 2009 6:37 pm

Newbie-after form submission return to home page?

Post by ducatigirl67 »

Hi,
php is a foreign language to me, dont know how to do 2 things.
When the form is filled out and submitted, then the "thank you" message is displayed on a blank white page.
I want the "thank you" to be displayed on a webpage with the navigation etc.
Or when the message comes up for it to be in a new window, so user can just go to website, currently, the fill form out, submit, message appears and website is gone.
I tried to add a url with target blank inside the code but it did not work.
I would really appreciate your help.

Heres the bit of code I think is needing variables.

// if the redirect option is set: redirect them
if ($redirect) {
header("Location: $redirect");
exit;
} else {
echo "Thank you for your submission, someone will be in contact with you soon.\n";
echo "<br><br>\n";

exit;
}

// <---------- THE END ----------> //
Eric!
DevNet Resident
Posts: 1146
Joined: Sun Jun 14, 2009 3:13 pm

Re: Newbie-after form submission return to home page?

Post by Eric! »

Here's an example. $redirect needs to be the url, if it is undefined then you'll get the simple thank you text, if $redirect is defined it will go to the redirected link. You should not echo anything to the browser (no HTML code) before calling the header() function.

Code: Select all

// if the redirect URL is set: redirect them
$redirect="http://yourdomain.com/thank you sucker.html";
if (isset($redirect)) {
header("Location: $redirect");
} else {
echo "Thank you for your submission, someone will be in contact with you soon.";
echo "<br /><br />";
exit;
}
edit: removed urlencode, because of stupid %2F
Last edited by Eric! on Mon Sep 14, 2009 9:28 am, edited 1 time in total.
User avatar
Eran
DevNet Master
Posts: 3549
Joined: Fri Jan 18, 2008 12:36 am
Location: Israel, ME

Re: Newbie-after form submission return to home page?

Post by Eran »

Don't use urlencode on any part of the URL containing functional slashes if you want them to work.
ducatigirl67
Forum Newbie
Posts: 22
Joined: Sun Sep 13, 2009 6:37 pm

Re: Newbie-after form submission return to home page?

Post by ducatigirl67 »

I pasted that snippet given to me, and it does not work. Says thankyou.htm not found.
I am VERY VERY new to php.
Can you write it out for me how it will work? Please.
ducatigirl67
Forum Newbie
Posts: 22
Joined: Sun Sep 13, 2009 6:37 pm

Re: Newbie-after form submission return to home page?

Post by ducatigirl67 »

ahhh I got it, thank you to the last person who posted, I removed the urlencode bit.
I'm rapt!
Thanks
Post Reply