Web Design and Development Forums

Directing user to a "thanks" page

This is a discussion on "Directing user to a "thanks" page" within the PHP Forum section. This forum, and the thread "Directing user to a "thanks" page are both part of the Program Your Website category.


Go Back   Webforumz.com > Program Your Website > PHP Forum

Welcome to Webforumz.com.
Register Now Register now!

Reply
 
LinkBack Thread Tools Rate Thread
Old May 1st, 2008, 15:11   #1 (permalink)
 
Join Date: Apr 2007
Location: UK
Age: 31
Posts: 49
Directing user to a "thanks" page

Hi

I know nothing about PHP and I am trying to come up with a basic contact form for my website. The form is no problem and I have cut and pasted some PHP which I have tried and tested OK for sending me mail.

The only thing I want to change is what happens after the form is submitted. I want to direct the client to a "thanks for your comments" page where they can then carry on navigating their way around the site. At the moment they just get a message saying "data has been submitted" and would have to use the back button to get back.

Can anyone advise me how to direct them to a different page? Below is the .php file I am using:
PHP: Select all

<?php 
if(isset($_POST['submit'])) { 
$to "xxxxxxxxxx@hotmail.com"
$subject "Matchday Programmes"
$name_field $_POST['name']; 
$email_field $_POST['email']; 
$message $_POST['message']; 
 
$body "From: $name_field\n E-Mail: $email_field\n Message:\n $message"
 
echo 
"Data has been submitted to $to!"
mail($to$subject$body); 
} else { 
echo 
"blarg!"

?>
Thanks in advance

Craig
__________________
http://www.sjohnsonart.co.uk

Last edited by aso186; May 1st, 2008 at 18:11. Reason: Use [php] tags
Craigj1303 is offline  
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!Spurl this Post!Reddit! Wong this Post!
Reply With Quote
Old May 1st, 2008, 16:48   #2 (permalink)
Up'n'Coming Member
 
Join Date: Feb 2006
Location: London
Age: 25
Posts: 99
Re: Directing user to a "thanks" page

Hi Craig,

The best way to do it would be to redirect the user to another page if the mail has been sent

PHP: Select all

// if the mail was sent successfully
if(mail($to$subject$body))

    
// redirect the user to another page
    
header('Location: http://www.example.com/'); exit;
}
else
{
    
// otherwise, tell them something went wrong
    
echo 'Oops!';

You must not output any html before the header() function, so no using echo/print or any whitespace before your opening php tags!

Give that a shot
__________________

jimz is offline  
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!Spurl this Post!Reddit! Wong this Post!
Reply With Quote
Old May 1st, 2008, 17:02   #3 (permalink)
 
Join Date: Apr 2007
Location: UK
Age: 31
Posts: 49
Re: Directing user to a "thanks" page

Hi,
Thanks for replying. As I say I have no PHP knowledge at all at the moment so I just pasted your suggested code in to my mailer.php file but now when I post the form I get this message:

Quote:
Parse error: syntax error, unexpected T_VARIABLE in /home/fhlinux163/a/anyoldirons.me.uk/user/htdocs/mailer.php on line 14
Can you tell me exactly where I should paste your code in relation to my PHP below and whether I need to remove anything from it?

PHP: Select all

 <?php 
if(isset($_POST['submit'])) { 
$to "xxxxxxxxxx@hotmail.com"
$subject "Matchday Programmes"
$name_field $_POST['name']; 
$email_field $_POST['email']; 
$message $_POST['message']; 

$body "From: $name_field\n E-Mail: $email_field\n Message:\n $message"

echo 
"Data has been submitted to $to!"
mail($to$subject$body); 
} else { 
echo 
"blarg!"

?>
Thanks & Rgs

Craig
__________________
http://www.sjohnsonart.co.uk

Last edited by aso186; May 1st, 2008 at 18:11.
Craigj1303 is offline  
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!Spurl this Post!Reddit! Wong this Post!
Reply With Quote
Old May 1st, 2008, 17:07   #4 (permalink)
Up'n'Coming Member
 
Join Date: Feb 2006
Location: London
Age: 25
Posts: 99
Re: Directing user to a "thanks" page

Replace this:

Code: Select all
echo "Data has been submitted to $to!"; 
mail($to, $subject, $body); 
} else { 
echo "blarg!"; 
}
with this:

Code: Select all
// if the mail was sent successfully
if(mail($to, $subject, $body))
{ 
    // redirect the user to another page
    header('Location: http://www.example.com/'); exit;
}
else
{
    // otherwise, tell them something went wrong
    echo 'Oops!';
}
__________________


Last edited by jimz; May 1st, 2008 at 17:09.
jimz is offline  
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!Spurl this Post!Reddit! Wong this Post!
Reply With Quote
Old May 5th, 2008, 16:36   #5 (permalink)
 
Join Date: Apr 2007
Location: UK
Age: 31
Posts: 49
Re: Directing user to a "thanks" page

Thanks a bunch jimz
__________________
http://www.sjohnsonart.co.uk
Craigj1303 is offline  
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!Spurl this Post!Reddit! Wong this Post!
Reply With Quote
Old May 5th, 2008, 20:25   #6 (permalink)
Nerdy Moderator
 
CloudedVision's Avatar
 
Join Date: Feb 2008
Location: In My Own Little World
Age: 14
Posts: 520
Blog Entries: 4
Re: Directing user to a "thanks" page

Personally I wouldn't do an HTTP redirect unless absolutely necessary. I would do something like this:

PHP: Select all

<?php 
if(isset($_POST['submit'])) { 
$to "xxxxxxxxxx@hotmail.com"
$subject "Matchday Programmes"
$name_field $_POST['name']; 
$email_field $_POST['email']; 
$message $_POST['message']; 
 
$body "From: $name_field\n E-Mail: $email_field\n Message:\n $message"
 
if(
mail($to$subject$body)) {?>Thank you message
<?php} else {?>Error message
<?php
} else { ?>Contact form
<?php 
?>
And I also added error handling in there, which is always a plus.
__________________
Take it easy

Other Road Design

WebForumz Moderator: HTML | Javascript | PHP
CloudedVision is offline  
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!Spurl this Post!Reddit! Wong this Post!
Reply With Quote
Reply

Thread Tools
Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On

Similar Threads
Thread Thread Starter Forum Replies Last Post
Creating a "tag" system to find relevant "related" pages MrQuestions PHP Forum 3 Mar 20th, 2008 23:06
[SOLVED] Show "Image" Depends On User "Status"? Monie ASP Forum 6 Oct 16th, 2007 01:22
? IS "meta name="robots" content="?" necessary in pages ? Love2Java New to Web Design 6 Aug 8th, 2007 13:48
What is code for "Only user with avatar" - i am using vbulletin basketmen PHP Forum 1 Apr 15th, 2007 19:13
window.opener.document["nameForm"].getElementById("someid").value; doesnt work drpompeii JavaScript Forum 0 Feb 17th, 2007 23:09



Latest Updates

All Points SEO Security Advisory - CHECK YOUR SITE NOW!

Creative Coding :: February 2008

Webforumz is sponsored by: WESH UK Web Hosting
All times are GMT. The time now is 19:16.

Sleep Study Scoring :: Free Bet :: Website Templates :: Online Betting :: Bookmakers :: Funny Quotes :: Internet Recruitment Software :: Microsoft CRM Experts :: Online Casino :: Decorated Christmas Trees :: Midwife Forums :: Football Betting :: Ecommerce Software :: Web Hosting :: Football Stats :: Dry Cleaning Collection :: xtreme wales - extreme clothing :: Apuestas :: Sharepoint Consultants :: Website Optimisation :: Office Clearance London :: Sharepoint Experts :: Sports Betting :: Casino :: Website Templates :: Web Design Development India :: Online Gambling

Powered by: vBulletin Version 3.7, Copyright ©2000 - 2008, Jelsoft Enterprises Limited.
© 2003-2008 Webforumz.com : All Rights Reserved
Search Engine Friendly URLs by vBSEO 3.2.0 RC6


1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59