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

问题描述:

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();
}

我想要做的是我有一个将数据插入表格的表格。 但是现在我想在表单中添加一个预览按钮来显示要插入的数据的预览,上传者可以在插入数据之前检查他所做的格式化。 p>

现在我想要 知道如何将表单提交到两个不同的页面并使用表单数据。 p>

我很困惑,因为使用表单的操作属性会使两个按钮都POST到同一页面。 p> \ n

我也试过下面的代码,但是如果数据太多而且data3是段落并且可以有长篇论文数据 p>

 ,它也会失败 ($ _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(); 
} 
  code>  pre> 
  div>

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']), '" />';