Reputation: 478
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();
}
Upvotes: 0
Views: 120
Reputation: 22921
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']), '" />';
Upvotes: 1