Code Newbie
News     Forums     Search     Members     Sign Up    

My Code Newbie
Username

Password

Articles/Snippets
ASP Classic
ASP.NET
C
C#
C++
HTML / CSS
Java
Javascript
Linux / BSD
Perl
PHP
Python
Ruby
SQL
VB 6
VB.NET

C.N. Friends
  Planet Rome

Link to Us!
Code Newbie
  Code Newbie
    forums
Old 02-28-2005, 09:27 AM   #1 (permalink)
googs
Registered User
 
Join Date: Feb 2005
Posts: 4
googs is on a distinguished road
PHP problem with a re-direct

I have a PHP-driven send mail script which gets its data from an HTML form
From what I can gather, the re-direct is not functioning properly

PROBLEM *** When the user clicks the submit button the browser's (any of them) URL window changes to the form's action (the PHP script)

All of the data submitted through the form is sent along with formatting It's just the user never gets re-directed.

I have made sure that all of the CMOD settings are set to 777

The funny thing is I originally wrote the script and it still works on the site I did it for a year ago.

Here's the code for the PHP script:

<?php
/************************************************** *\
* PHP 4.1.0+ version of email script.
\************************************************* **/
//
//
$sendTo = "user@AOL.com";
$subject = "Your request from Design";
//
//
$headers = "From: " . $_POST["companyname"];
$headers .= "<" . $_POST["email"] .">\r\n";
// next include a Reply-To:
$headers .= "Reply-To: " . $_POST["email"];
//
//
$message = $_POST["companyname"] ."\r\n";
$message .= $_POST["address"] ."\r\n";
$message .= $_POST["phone"] ."\r\n";
$message .= $_POST["email"] ."\r\n\n";
$message .= $_POST["message"];
//
//
$redirect = "thanks.html";
mail($sendTo, $subject, $message, $headers);
?>

Here's the form code snippet:

<form action="phpmail.php" method="post" enctype="multipart/form-data" name="form1">
<p>
<input name="companyname" type="text" id="companyname4">
Company Name*</p>
<p>
<input name="address" type="text" id="address4">
Address
<input type=hidden name="redirect" value="thanks.html">
</p>
<p>
<input name="phone" type="text" id="phone4">
Phone</p>
<p>
<input name="email" type="text" id="email4">
Email*</p>
<p>
<textarea name="message" id="textarea3"></textarea>
Questions</p>
<p>
<input type="submit" name="Submit" value="Submit">
</p>
<p>
<input type="reset" name="Submit2" value="Reset">
</p>
</form>


Can this have anything to do with the fact that I have another form on my site of which the redirect = thanks.html (This is the re-direct page of the script that has the problem)?

Any help on this issue is greatly appreciated
googs is offline   Reply With Quote
Old 02-28-2005, 09:55 AM   #2 (permalink)
idx
Senior Grasshopper
 
idx's Avatar
 
Join Date: Jun 2003
Location: FL
Posts: 317
idx is on a distinguished road
How are you performing the redirect? (didn't see it in the above example)

It shouldn't matter that you have a hidden redirect field in the html page if you're manually setting it with the php page.

-r
idx is offline   Reply With Quote
Old 02-28-2005, 10:03 AM   #3 (permalink)
googs
Registered User
 
Join Date: Feb 2005
Posts: 4
googs is on a distinguished road
R

Forgive me but I am a PHP newbie and I'm a little confused about your question
In the PHP script I have the re-direct variable assigned as such...
$redirect = "thanks.html";

Is this along with the hidden field value embedded within the actual HTML form... <input type=hidden name="redirect" value="thanks.html">


What else do I need to get this script functioning correctly?

What am I missing here?

Thanks for all of your help

Keith
googs is offline   Reply With Quote
Old 02-28-2005, 10:21 AM   #4 (permalink)
sde
Moderator
 
sde's Avatar
 
Join Date: May 2002
Location: us.ca
Posts: 4,475
sde is on a distinguished road
you are missing the redirect. also, you probably only want the mail function to execute if post data was sent. here is an example that i haven't tested yet.
PHP Code:
<?php
/************************************************** *\
* PHP 4.1.0+ version of email script.
\************************************************* **/
//
//
if($_POST){
  
$sendTo "user@AOL.com";
  
$subject "Your request from Design";
  
//
  //
  
$headers "From: " $_POST["companyname"];
  
$headers .= "<" $_POST["email"] .">\r\n";
  
// next include a Reply-To:
  
$headers .= "Reply-To: " $_POST["email"];
  
//
  //
  
$message $_POST["companyname"] ."\r\n";
  
$message .= $_POST["address"] ."\r\n";
  
$message .= $_POST["phone"] ."\r\n";
  
$message .= $_POST["email"] ."\r\n\n";
  
$message .= $_POST["message"];
  
//
  //
  
  
mail($sendTo$subject$message$headers);
  
header("location: thanks.html");
  exit;
}
?>

Here's the form code snippet:

<form action="phpmail.php" method="post" enctype="multipart/form-data" name="form1">
<p>
<input name="companyname" type="text" id="companyname4">
Company Name*</p>
<p>
<input name="address" type="text" id="address4">
Address
<input type=hidden name="redirect" value="thanks.html">
</p>
<p>
<input name="phone" type="text" id="phone4">
Phone</p>
<p>
<input name="email" type="text" id="email4">
Email*</p>
<p>
<textarea name="message" id="textarea3"></textarea>
Questions</p>
<p>
<input type="submit" name="Submit" value="Submit">
</p>
<p>
<input type="reset" name="Submit2" value="Reset">
</p>
</form>
__________________
Mike
sde is offline   Reply With Quote
Old 02-28-2005, 10:58 AM   #5 (permalink)
idx
Senior Grasshopper
 
idx's Avatar
 
Join Date: Jun 2003
Location: FL
Posts: 317
idx is on a distinguished road
Quote:
Originally Posted by googs
What else do I need to get this script functioning correctly?
What am I missing here?
sde's example should get you rolling. You just needed to add the actual html header that performs the redirect.

You can either hardcode it in the php script, or rely on the value in the html form. Something like the following might be useful:

PHP Code:
  // skipping other php stuff....
  
$redirect = (isset($_POST['redirect'])) ? $_POST['redirect'] : 'thanks.html';
  
header("location: {$redirect}"); 
  exit; 
So if the html form specifies a redirect page, the php script will use it. Otherwise it redirects to 'thanks.html' by default.


-r
idx is offline   Reply With Quote
Old 02-28-2005, 11:16 AM   #6 (permalink)
googs
Registered User
 
Join Date: Feb 2005
Posts: 4
googs is on a distinguished road
r,

I have a question regarding your last post
Where you write, "...// skipping other php stuff....
$redirect = (isset($_POST['redirect'])) ? $_POST['redirect'] : 'thanks.html';
header("location: {$redirect}");
exit; "
the skipping other PHP stuff comment means that I append the code above to the end of the PHP script or replace the code with the code I posted in this post?

Thanks
googs is offline   Reply With Quote
Old 02-28-2005, 11:19 AM   #7 (permalink)
sde
Moderator
 
sde's Avatar
 
Join Date: May 2002
Location: us.ca
Posts: 4,475
sde is on a distinguished road
he means replace the lines that start with header and exit, with the 3 lines in his example.
__________________
Mike
sde is offline   Reply With Quote
Old 03-01-2005, 07:54 AM   #8 (permalink)
googs
Registered User
 
Join Date: Feb 2005
Posts: 4
googs is on a distinguished road
Guys, I wanted to sincerely thank you for all of your assistance. I may be pushing my luck here, but what the heck. How would I go about putting in the existing code you guys outlined, code that will prevent a user from submitting multiple forms. I know this probably has something to do setting session variables, right?

Thanks again
googs is offline   Reply With Quote
Old 03-01-2005, 04:12 PM   #9 (permalink)
idx
Senior Grasshopper
 
idx's Avatar
 
Join Date: Jun 2003
Location: FL
Posts: 317
idx is on a distinguished road
It depends on the nature of the application. If you just want something to stop uses from crazy clicking, then some javascript might be a good thing to add.

eg:
(excuse my shoddy js)

Code:
<script>
<!--
var sv = '';
function do_form1_submit() {
   sv = document.form1.Submit.value;
   document.form1.Submit.disabled = true;
   document.form1.Submit.value = 'Please wait...';

   setTimeout('document.form1.Submit.disabled = false;', 10000);
   setTimeout('document.form1.Submit.value = sv;', 10000);

}
//-->
</script>
<form action="phpmail.php" method="post" enctype="multipart/form-data" name="form1" onSubmit="do_form1_submit();">
<p>
<input name="companyname" type="text" id="companyname4">
Company Name*</p>
<!-- [snip form] -->
<input type="submit" name="Submit" value="Submit">
</p>
<p>
<input type="reset" name="Submit2" value="Reset">
</p>
</form>

... have to run now, but I'll see if I can work up a php session example if the JS method wont work.

-r

Last edited by idx; 03-01-2005 at 04:53 PM.
idx is offline   Reply With Quote
Reply

Bookmarks

Thread Tools
Display Modes

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
PHP vs .NET Redline Lounge 1 11-24-2004 06:10 AM
php 5 problem Amaranthine PHP 4 06-29-2004 10:25 PM
direct x9 problem Apodysophilia Windows 2 07-25-2003 09:29 AM
Direct X problem... Mr.Anderson Lounge 2 05-22-2003 04:19 PM
PHP / JS problem bdl HTML, XML, Javascript, AJAX 2 03-13-2003 08:53 AM


All times are GMT -8. The time now is 07:19 PM.


Powered by vBulletin® Version 3.7.0
Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.
Search Engine Optimization by vBSEO 3.0.0 RC8





Copyright © 2000-2008, Milano Interactive
Web Hosting provided by Portal 360 Web Hosting