doutang7415 2017-06-21 05:53
浏览 73
已采纳

如何将表单发布到两个不同的页面并在提交的页面中使用表单数据?

What I am trying to do is I have a form which inserts data into a table. But now I want to add a preview button to the form to show a preview of the data to be inserted and uploader can check the formatting he has done before inserting data.

Now I want to know how to submit form to two different pages and use the form data.

I am confused as Using action attribute of form will make both buttons to POST to same page.

I have also tried code below, but it will also fail if the data is too much and as data3 is paragraph and can have long essay data

if( $_SERVER["REQUEST_METHOD"] == "POST" && isset($_POST['preview']) ){
    $data1 = trim($_POST['data1']);
    $data2 = trim($_POST['data2']);
    $data3 = trim($_POST['data3']);
    header("location: preview.php?preview=true&data1=$data1&data2=$data2&data3=$data3");
    exit();
}
  • 写回答

1条回答 默认 最新

  • dongmaopiao0901 2017-06-21 05:56
    关注

    Use a session, and store the post data in an array, or output the variables in a hidden form on preview page.

    Example 1:

    session_start();
    
    $_SESSION['form_data'] = [
        'data1' => $_POST['data1']
        ...
    ];
    

    Example 2:

    echo '<input type="hidden" name="data1" value="', htmlspecialchars($_POST['data1']), '" />';
    
    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?

悬赏问题

  • ¥15 Attention is all you need 的代码运行
  • ¥15 一个服务器已经有一个系统了如果用usb再装一个系统,原来的系统会被覆盖掉吗
  • ¥15 使用esm_msa1_t12_100M_UR50S蛋白质语言模型进行零样本预测时,终端显示出了sequence handled的进度条,但是并不出结果就自动终止回到命令提示行了是怎么回事:
  • ¥15 前置放大电路与功率放大电路相连放大倍数出现问题
  • ¥30 关于<main>标签页面跳转的问题
  • ¥80 部署运行web自动化项目
  • ¥15 腾讯云如何建立同一个项目中物模型之间的联系
  • ¥30 VMware 云桌面水印如何添加
  • ¥15 用ns3仿真出5G核心网网元
  • ¥15 matlab答疑 关于海上风电的爬坡事件检测