我想知道如何将表单数据从php处理页面传递到成功页面。
如何将$ orderid传递给我的成功页面?我只需要传递这个值,这样简单就可以了! :-P
<?php
$stamp = date("Ymdhis");
$random_id_length = 6;
$rndid = generateRandomString( $random_id_length );
$orderid = $stamp ."-". $rndid;
function generateRandomString($length = 10) {
$characters = '0123456789';
$randomString = '';
for ($i = 0; $i < $length; $i++) {
$randomString .= $characters[rand(0, strlen($characters) - 1)];
}
return $randomString;
}
$repairtitle = $_POST['courierrepairtitle'];
$repairconsole = $_POST['courierrepairconsole'];
$repairprice = $_POST['courierrepairprice'];
$outwardpostage = $_POST['outwardpostage'];
$returnpostage = $_POST['returnpostage'];
$name = $_POST['couriername'];
$email = $_POST['courieremail'];
$homephone = $_POST['courierhomephone'];
$mobilephone = $_POST['couriermobilephone'];
$address1 = $_POST['courieraddress1'];
$address2 = $_POST['courieraddress2'];
$address3 = $_POST['courieraddress3'];
$city = $_POST['couriercity'];
$county = $_POST['couriercounty'];
$postcode = $_POST['courierpostcode'];
$country = $_POST['couriercountry'];
$formcontent=" Order No: $orderid \n \n Repair Title: $repairtitle \n Console: $repairconsole \n Price: $repairprice \n \n Outward Postage: $outwardpostage \n Return Postage: $returnpostage \n \n Name: $name \n Email: $email \n Home Phone: $homephone \n Mobile Phone: $mobilephone \n \n Address1: $address1 \n Address2: $address2 \n Address3: $address3 \n City: $city \n County: $county \n Postcode: $postcode \n Country: $country ";
$recipient = "info@example.co.uk";
$subject = "Order Form";
$mailheader = "From: $email \r\n";
// Test to see if variables are empty:
if(!empty($name) && !empty($email) && !empty($homephone) && !empty($address1) && !empty($city) && !empty($postcode) && !empty($country)){
// Test to see if the mail sends successfully:
if(mail($recipient, $subject, $formcontent, $mailheader)){
header("Location: http://www.example.co.uk/courier-mailer-success.htm");
}else{
header("Location: http://www.example.co.uk/courier-mailer-fail.htm");
}
}else{
header("Location: http://www.example.co.uk/courier-mailer-fail.htm");
}
exit;
?>
答案 0 :(得分:5)
您可以将其作为GET参数放在URL的末尾。
'success.php?orderid=one'
该页面上的访问:
$_GET['item']
答案 1 :(得分:2)
您可以将数据存储在session中,然后从成功页面访问
答案 2 :(得分:0)
在这种情况下,session变量会很好用。这些用于在页面之间保留数据,这样可以在整个应用程序中访问此变量,而无需在必要时作为每个页面的GET参数传递。在文件的最顶部,您需要开始会话:
<?php
session_start();
$stamp = date("Ymdhis");
...
从这里开始,您现在可以分配会话变量。代码如下:
if(mail($recipient, $subject, $formcontent, $mailheader)){
$_SESSION['orderid'] = $orderid;
header("Location: http://www.example.co.uk/courier-mailer-success.htm");
}
从此处重定向到您的成功页面。 您需要将courier-mailer-success.htm转换为.php文件才能访问此数据。您还需要将session_start();
添加到成功页面的顶部以访问会话数据。您可以像这样访问您的变量:
<?php
session_start();
...
$id = $_SESSION['orderid'];
echo $id;