0

我想知道如何将表单数据从 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;
?>
4

3 回答 3

5

您可以将其作为 GET 参数放在 URL 的末尾。

'success.php?orderid=one'

在该页面上访问它:

 $_GET['item']
于 2013-07-11T17:50:29.130 回答
2

您可以将数据存储在会话中并从成功页面访问它

于 2013-07-11T17:50:08.397 回答
0

在这种情况下,会话变量会很好用。这些用于在页面之间持久化数据,这带来了能够在整个应用程序中访问此变量的好处,而不必在必要时为每个页面传递 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;
于 2013-07-11T17:54:01.450 回答