[SOLVED] PHP contact form redirect to same form

This is a discussion on "[SOLVED] PHP contact form redirect to same form" within the PHP Forum section. This forum, and the thread "[SOLVED] PHP contact form redirect to same form are both part of the Program Your Website category.


 Subscribe in a reader

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

Notices




Reply
 
LinkBack Thread Tools
  #1  
Old Jan 24th, 2008, 05:30
Junior Member
Join Date: Nov 2007
Location: Oregon
Posts: 23
Thanks: 0
Thanked 0 Times in 0 Posts
[SOLVED] PHP contact form redirect to same form

Sorry if that title was confusing... I wasn't sure how to get it all in!

I have a contact form on my website at the page http://www.centraloregonweddingflowe.../contacts.html

Currently, my php email works fine and sends an email to me, but when it is submitted, a new blank page is brought up. Confusing for the sender!

I would love to have the same contacts.html page reload, BUT with the words "Thank You" in the text box area where the user types their message.

Is this possible? Or maybe I should ask, advisable?

Thanks in advance for your help!
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!Spurl this Post!Reddit! Wong this Post!
Reply With Quote

  #2  
Old Jan 24th, 2008, 05:40
alexgeek's Avatar
Moderator

SuperMember
Join Date: Jul 2007
Location: Webforumz 24/7
Age: 15
Posts: 3,812
Blog Entries: 9
Thanks: 2
Thanked 2 Times in 2 Posts
Re: PHP contact form redirect to same form

Post your email sending code, we can just add a simple header.
Last Blog Entry: 3D Chess in your browser! (Mar 14th, 2008)
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!Spurl this Post!Reddit! Wong this Post!
Reply With Quote
  #3  
Old Jan 24th, 2008, 05:46
Junior Member
Join Date: Nov 2007
Location: Oregon
Posts: 23
Thanks: 0
Thanked 0 Times in 0 Posts
Re: PHP contact form redirect to same form

Ok, but I apologize that it's not validating the fields yet... I like to get it working then start fiddling with it, so I can see where I went wrong.

So with that disclaimer, here it is:
Code: Select all
<?
$destination="info@centraloregonweddingflowers.com";
$name=$_POST['name1'];
$email=$_POST['email'];
$from = 'info@centraloregonweddingflowers.com';
$cell=$_POST['cell'];
$phone=$_POST['number'];
$mes=$_POST['message1'];
$subject="Message from $name" ;
$header="From: $from\n";
$mes="Name: $name\n
Email: $email\n
Phone: $phone\n
Cell: $cell\n
Comments: $mes\n";
mail($destination,$subject,$mes,$header); ?>
Thanks for your help!
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!Spurl this Post!Reddit! Wong this Post!
Reply With Quote
  #4  
Old Jan 24th, 2008, 05:51
alexgeek's Avatar
Moderator

SuperMember
Join Date: Jul 2007
Location: Webforumz 24/7
Age: 15
Posts: 3,812
Blog Entries: 9
Thanks: 2
Thanked 2 Times in 2 Posts
Re: PHP contact form redirect to same form

Okay add under the last line:
PHP: Select all

header("Location: http://www.centraloregonweddingflowers.com/contacts.php?thankyou"); 

Notice that your contact form page has to be renamed to .php.

Then
put this where you want the thank you to appear:
PHP: Select all

if(isset($_POST['thankyou'])) {
echo 
'Thank you!';

Last Blog Entry: 3D Chess in your browser! (Mar 14th, 2008)
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!Spurl this Post!Reddit! Wong this Post!
Reply With Quote
  #5  
Old Jan 24th, 2008, 06:10
Junior Member
Join Date: Nov 2007
Location: Oregon
Posts: 23
Thanks: 0
Thanked 0 Times in 0 Posts
Re: PHP contact form redirect to same form

Thank you! I have a few assumptions and questions about this:

1. I need to put that new last line inside the php script (before ?>) right?

2. Can I make a copy of my current contacts.html page and save it as a .php page just used for this purpose, keeping my html page also to avoid updating all my links?


3. Does the isset/echo bit go in the contacts.php page? If I want it to show up in the message textbox, do I need to place it somewhere in this area?
Code: Select all
        <td valign="top"><span style="color:#999999">Message</span></td>
                    <td><textarea class="mess" name="message1"></textarea></td>
                </tr>
Thanks so much for your help and patience!
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!Spurl this Post!Reddit! Wong this Post!
Reply With Quote
  #6  
Old Jan 24th, 2008, 06:19
alexgeek's Avatar
Moderator

SuperMember
Join Date: Jul 2007
Location: Webforumz 24/7
Age: 15
Posts: 3,812
Blog Entries: 9
Thanks: 2
Thanked 2 Times in 2 Posts
Re: PHP contact form redirect to same form

1. Yes.
2. Yes.
3. Yes. You can place it wherever you like.
E.G.
<h1>Contact Page</h1>

To make it appear in the <h1>
You'd use:
HTML: Select all
<h1>Contact Page <?php 
if(isset($_POST['thankyou'])) {
echo ', Thank you!';
} ?>
This would show: <h1>Contact Page</h1> if the email hadn't been sent yet. And <h1>Contact Page, Thank you!</h1> if it had
Last Blog Entry: 3D Chess in your browser! (Mar 14th, 2008)
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!Spurl this Post!Reddit! Wong this Post!
Reply With Quote
  #7  
Old Jan 24th, 2008, 06:23
Junior Member
Join Date: Nov 2007
Location: Oregon
Posts: 23
Thanks: 0
Thanked 0 Times in 0 Posts
Re: PHP contact form redirect to same form

Ah, you are a lifesaver!

Now on to validation, I promise.

Thanks again. I appreciate you!
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!Spurl this Post!Reddit! Wong this Post!
Reply With Quote
  #8  
Old Jan 24th, 2008, 06:50
alexgeek's Avatar
Moderator

SuperMember
Join Date: Jul 2007
Location: Webforumz 24/7
Age: 15
Posts: 3,812
Blog Entries: 9
Thanks: 2
Thanked 2 Times in 2 Posts
Re: PHP contact form redirect to same form

You're welcome, Good Luck validating. It's mainly just a few alt attributes missing.
Last Blog Entry: 3D Chess in your browser! (Mar 14th, 2008)
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!Spurl this Post!Reddit! Wong this Post!
Reply With Quote
  #9  
Old Jan 24th, 2008, 06:50
Junior Member
Join Date: Nov 2007
Location: Oregon
Posts: 23
Thanks: 0
Thanked 0 Times in 0 Posts
Re: PHP contact form redirect to same form

Well, I still appreciate you, but I'm getting another error.

When I hit submit, my email is still sent, but I get a new page with the following message:

The document name you requested (/index.php) could not be found on this server. However, we found documents with names similar to the one you requested.Available documents: Any ideas? I am running php files in different folders for this website, so I probably have an index.php file (or two) around. Is there a reason it's looking for one here?

(By the way, I took out the "?thankyou" and reloaded the page to see if that would help. I was getting the same message before.)
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!Spurl this Post!Reddit! Wong this Post!
Reply With Quote
  #10  
Old Jan 24th, 2008, 06:57
alexgeek's Avatar
Moderator

SuperMember
Join Date: Jul 2007
Location: Webforumz 24/7
Age: 15
Posts: 3,812
Blog Entries: 9
Thanks: 2
Thanked 2 Times in 2 Posts
Re: PHP contact form redirect to same form

You have this exact line right?
PHP: Select all

header("Location: http://www.centraloregonweddingflowers.com/contacts.php?thankyou"); 

That should definitely work, I just checked and it is a real page..
Why the hell would it ask for index.php? This is baffling me.
I'll have another look later.
Last Blog Entry: 3D Chess in your browser! (Mar 14th, 2008)
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!Spurl this Post!Reddit! Wong this Post!
Reply With Quote
  #11  
Old Jan 24th, 2008, 07:09
Junior Member
Join Date: Nov 2007
Location: Oregon
Posts: 23
Thanks: 0
Thanked 0 Times in 0 Posts
Re: PHP contact form redirect to same form

Yes, here is my whole file:
Code: Select all
<?
$destination="info@centraloregonweddingflowers.com";
$name=$_POST['name1'];
$email=$_POST['email'];
$from = 'info@centraloregonweddingflowers.com';
$cell=$_POST['cell'];
$phone=$_POST['number'];
$mes=$_POST['message1'];
$subject="Message from $name" ;
$header="From: $from\n";
$mes="Name: $name\n
Email: $email\n
Phone: $phone\n
Cell: $cell\n
Comments: $mes\n";
mail($destination,$subject,$mes,$header); 
header("Location: http://www.centraloregonweddingflowers.com/contacts.php?thankyou");
?>
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!Spurl this Post!Reddit! Wong this Post!
Reply With Quote
  #12  
Old Jan 28th, 2008, 02:04
Junior Member
Join Date: Nov 2007
Location: Oregon
Posts: 23
Thanks: 0
Thanked 0 Times in 0 Posts
Re: PHP contact form redirect to same form

I'm wondering if there is a more straightforward way to solve my problem.

What about redirecting the page back to the original "contact.html" page, with a pop-up box that says "Thank you" and a button to close it.

Would this be easier? Or is there a very simple answer that I should be looking at? I really just want the user to know that their message was sent and allow them to continue browsing.

Thanks in advance!
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!Spurl this Post!Reddit! Wong this Post!
Reply With Quote
  #13  
Old Jan 28th, 2008, 04:44
Highly Reputable Member
Join Date: Apr 2007
Location: Willich, Germany
Age: 20
Posts: 593
Blog Entries: 2
Thanks: 0
Thanked 0 Times in 0 Posts
Re: PHP contact form redirect to same form

If you check the stickies, you'll find a basic tutorial on sending an email using PHP.
here: http://www.webforumz.com/php-forum/6...validating.htm
See if that helps....
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!Spurl this Post!Reddit! Wong this Post!
Reply With Quote
  #14  
Old Jan 28th, 2008, 14:37
masonbarge's Avatar
Highly Reputable Member
Join Date: Jan 2006
Location: Atlanta GA
Posts: 631
Thanks: 0
Thanked 0 Times in 0 Posts
Re: PHP contact form redirect to same form

I'll try to give a few suggestions, easiest to hardest.

First, try inserting "$_GET" for "$_POST" in the little target page script. The whole thing might work.

If not, are you using some kind of mod_rewrite? Probably not, but that can mess up a URL.

If not, check to make sure your server isn't forcing you into "safe mode". Normally this would give you a more specific error message but it could easily mess up a redirect.

One idea, of course, is to create a page named "index.php" and see what happens.

The error message you are getting is a "status 300" http header, which means that your page is requesting multiple addresses -- one (apparently) automatically to the url "www.centraloregonweddingflowers.com/", which then like any empty directory request searches for an "index.php" page, and a second one specified by "header()". You might try commenting out the "header()" line, submit, and copy down the URL of the blank white page that you were getting before.

An HTTP problem is beyond the scope of this forum. though. You might want to ask your server host about this problem. Redirecting through use of the PHP header() function is too valuable not to work right.

In the meantime, do something that works. Like, after the mail has been sent, echo (or just close php and use html) a nice blank page with the words "Your mail has been sent. Thank You!", a couple of breaks, and a link or two, like
Code: Select all
<a href="./whereveryourwantthemtogo.php">Click to continue . . .</a>
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!Spurl this Post!Reddit! Wong this Post!
Reply With Quote
  #15  
Old Jan 29th, 2008, 20:28
Junior Member
Join Date: Nov 2007
Location: Oregon
Posts: 23
Thanks: 0
Thanked 0 Times in 0 Posts
Re: PHP contact form redirect to same form

Well, I finally got a simple solution to work.

After my original php email script, I just added the code for the html page I wanted to direct it to (since I only had one anyway) with a link back to the contact page.

Sometimes simplest is best, even if complicated is more exciting!

Thanks so much for all your help everyone!
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

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
[SOLVED] PHP contact form problem fl0w PHP Forum 12 Jan 31st, 2008 17:56
[SOLVED] PHP Contact Form Stuart PHP Forum 8 Dec 4th, 2007 17:42
[SOLVED] Contact Form Help danny322 PHP Forum 3 Nov 7th, 2007 16:05
[SOLVED] PHP Contact Form Stuart PHP Forum 9 Oct 20th, 2007 00:48
Redirect for an ASP Contact Form Sporky Classic ASP 9 Jan 26th, 2007 13:00


All times are GMT. The time now is 01:53.


Powered by vBulletin®
Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.
Search Engine Optimization by vBSEO 3.2.0 RC8
© 2003-2008 Webforumz.com : All Rights Reserved