What are common methods to pass data from a form to a popup window in PHP?
To pass data from a form to a popup window in PHP, you can use JavaScript to open the popup window and pass the form data as URL parameters. This can be achieved by submitting the form to a PHP script that generates the URL with the form data, and then using JavaScript to open the popup window with the generated URL.
<?php
if ($_SERVER["REQUEST_METHOD"] == "POST") {
// Process form data here
// Generate URL with form data
$data1 = $_POST['data1'];
$data2 = $_POST['data2'];
$url = "popup.php?data1=$data1&data2=$data2";
// Open popup window with generated URL
echo "<script>window.open('$url', 'Popup', 'width=400,height=400');</script>";
}
?>
<!-- Form to submit data -->
<form method="post" action="<?php echo $_SERVER['PHP_SELF']; ?>">
<input type="text" name="data1">
<input type="text" name="data2">
<button type="submit">Submit</button>
</form>