views:

25

answers:

3

I designed a form that emails the results when submitted. The PHP script will show a thank you page upon success. Is it possible to place the the "name" field in a separate thank you page?

Here is my code for the form:

<?php
$name = $_REQUEST['name'] ;
$carenumber= $_REQUEST['carenumber'] ;
$email = $_REQUEST['email'] ;
$topic = $_REQUEST['topic'] ;
$message = $_REQUEST['message'] ;

$Body = "";
$Body .= "Name: ";
$Body .= $name;
$Body .= "\n";
$Body .= "\n";
$Body .= "Caregiver Number: ";
$Body .= $carenumber;
$Body .= "\n";
$Body .= "\n";
$Body .= "Email Address: ";
$Body .= $email;
$Body .= "\n";
$Body .= "\n";
$Body .= "Topic: ";
$Body .= $topic;
$Body .= "\n";
$Body .= "\n";
$Body .= "Message: ";
$Body .= $message;
$Body .= "\n";

mail( "[email protected]", "Message From Myorphan.com Contact Page",
$Body, "From: $email" );

header( "Location: http://www.feedmyorphan.com/contact_confirm.htm" );
?>
A: 

If I understand you correctly...

...try setting the name field as a $_SESSION variable, and accessing it through $_SESSION on the thank you page.

kaese
Do you have an example? Not sure how to follow.
Erik
Here is a good tutorial on using session variables:http://www.w3schools.com/PHP/php_sessions.aspThis will enable you to access the name variable on any page, providing the session is started correctly.
kaese
A: 

You would need to make the thank you page a PHP page (using the .php extension), then, in your header in this code sample you have provided, place:

header("Location: http://www.feedmyorphan.com/contact_confirm.php?name=" . urlencode($name));

Then, on the thank you page, use <?php echo $_GET['name'] ?> anywhere on the page.

Evan Mulawski
Ok... But in the thank you page, do I simply place $name anywhere on the page?
Erik
`<?php echo $_GET['name']; ?>`
Dave Kiss
It doesn't work: <div class="mr">Thank you echo $_GET['name'];</div>
Erik
Do I need something in the header of the thank you page? How do i make reference to the echo? Thanks for all your help
Erik
You need to use PHP tags around the call.
Dave Kiss
Like this: <echo $_GET['name'];>
Erik
See my revised comment above.
Dave Kiss
Thank you.. it worked great. Should this work with all the browsers? Thank you so much for your follow through! Wonderful.
Erik
This method doesn't have to do with browsers since it is all server side. It isn't very safe, though, because anyone can change the name value in the address bar and insert whatever information into your page that they'd like, including malicious code. I'd use the session method shown in my answer below.
Dave Kiss
Use: <p> <?php echo $_GET['name'] ?> </p> - But Dave Kiss is correct regarding the security of this method; the session should be started on the page that contains the form and ended on the thank you page.
Evan Mulawski
A: 

Yes, you need to use SESSIONS and send the cookie data to the second script using PHP. Here is an example using cURL.

session_start();
$_SESSION['name'] = $name;   
passSession();

function passSession(){
 $strCookie = 'PHPSESSID=' . $_COOKIE['PHPSESSID'] . '; path=/';
 session_write_close();

 $ch = curl_init();
 curl_setopt($ch, CURLOPT_URL,"http://www.feedmyorphan.com/contact_confirm.php");
 curl_setopt($ch, CURLOPT_COOKIE, $strCookie);
 curl_exec ($ch);
 curl_close ($ch);
}

Then, in your second script, call for the session and echo the session variable

session_start();
echo $_SESSION['name'];

Also, be sure to validate and sanitize your input to ensure the data being submitted is as accurate as possible.

Dave Kiss