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 动力学代码报错,维度不匹配
  • ¥15 Power query添加列问题
  • ¥50 Kubernetes&Fission&Eleasticsearch
  • ¥15 有没有帮写代码做实验仿真的
  • ¥15 報錯:Person is not mapped,如何解決?
  • ¥30 vmware exsi重置后登不上
  • ¥15 c++头文件不能识别CDialog
  • ¥15 Excel发现不可读取的内容
  • ¥15 关于#stm32#的问题:CANOpen的PDO同步传输问题
  • ¥20 yolov5自定义Prune报错,如何解决?