dp198879 2011-05-22 10:47
浏览 24
已采纳

表单方法 - POST删除以前的数据

I am trying to get some data from page to page and then mail them.

So from one form I am getting a title of item :

//Form1
<form  class="orderFormFields" method="post" action="order">
<input type="hidden" name="productName" value="<?php the_title(); ?>">
<input class="oButton" value="Order" type="submit"/>
</form>

And then is another form (next page) with other fields witch I need to mail :

<?php 
//getting a variable from previous form
$product = $_POST['productName'];

if(isset($_POST['submit'])) 
{
$name = $_POST['order_name'];
$mail = $_POST['email'];
$phone = $_POST['mobile'];
$date = $_POST['date'];
$comment = $_POST['comment'];



//simple mail function goes here

$done = true;
}

?>

//Form2 goes here

So if I insert <?php echo $product; ?> before if(isset($_POST['submit'])) I can see my variable from previous page and all works just find. But when I am inserting that same variable in mail function witch is inside if(isset($_POST['submit'])) , I cant mail that variable, seems like it is empty.

Does form method POST delete all previous form data? Because, if I change my Form1 method to GET and $product = $_POST['productName']; to $product = $_GET['productName']; I am getting that variable after Form2 submit and I can mail that variable. But I would like to prefer using POST method, because of nice URL.

  • 写回答

1条回答 默认 最新

  • dongtuo5262 2011-05-22 10:50
    关注

    You forgot to name your submit button so there is no $_POST['submit']

    <input class="oButton" value="Order" type="submit" name="submit" />
    

    EDIT: Okay, $_POST is array and have its values only after the post request. If you make another post request or change the page the previous values of $_POST are deleted and these from the new request are stored. You can store data from the first post in the sessions for example -

    $_SESSION['postData']['form1'] = $_POST;
    
    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?

悬赏问题

  • ¥15 2024-五一综合模拟赛
  • ¥15 下图接收小电路,谁知道原理
  • ¥15 装 pytorch 的时候出了好多问题,遇到这种情况怎么处理?
  • ¥20 IOS游览器某宝手机网页版自动立即购买JavaScript脚本
  • ¥15 手机接入宽带网线,如何释放宽带全部速度
  • ¥30 关于#r语言#的问题:如何对R语言中mfgarch包中构建的garch-midas模型进行样本内长期波动率预测和样本外长期波动率预测
  • ¥15 ETLCloud 处理json多层级问题
  • ¥15 matlab中使用gurobi时报错
  • ¥15 这个主板怎么能扩出一两个sata口
  • ¥15 不是,这到底错哪儿了😭