开发者

Place Name from Form Results in thank you page?

开发者 https://www.devze.com 2023-01-20 19:18 出处:网络
I designed a form that emails the results when submitted.The PHP script will show a thank you page upon success.Is it pos开发者_Python百科sible to place the the \"name\" field in a separate thank you

I designed a form that emails the results when submitted. The PHP script will show a thank you page upon success. Is it pos开发者_Python百科sible 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( "eriksnet@mac.com", "Message From Myorphan.com Contact Page",
$Body, "From: $email" );

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


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.


If I understand you correctly...

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


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.

0

精彩评论

暂无评论...
验证码 换一张
取 消