简体   繁体   中英

How to get values from one form to another

Can any one help me to get the values of two different dates when I press a button to another form? For now I'm able to get only the value of one date. This my php scripts:

<?php
require_once 'incs/functions.php';
require_once 'classes/Database.php';

global $database;

$from_date = isset($_POST['from_date']) != "" ? $_POST['from_date']:       
date('Y-m-d');
$to_date   = isset($_POST['to_date']) != "" ? $_POST['to_date']: date('Y-m-  
d');

$urlP = "print_one.php? uid= $from_date";
?>

Here's code for the button:

<?php echo "<a onclick=\"return windowpop('".$urlP."', 700, 500)\" href='#'>
<button class='btn btn-round btn-white btn-size:50px;' style='alignment- 
 baseline:left-90px;'>Print</button></a>"; 
 ?>

As you can see, when I press the button the "print_one.php" form opens with only the "from_date" value. How could I get both values of "from_date" and "to_date" to the second form known as "print_one.php" when I press the button so that I can use them to run a query.

Please help.

As far as i know, query string (which is what you urlIP contains) is accessible through $_GET, not $_POST. For $_POST you need to submit a form. The difference would then be that values from_date and to_date would not be visible in the query string, but sent in the POST header of the HTTP request.

Even further, if choosing POST method instead of GET, your receiving script would need to redirect this HTTP POST call to another page(or the same), so that if you press back in browser, you wouldn't get that window saying "there is some data to be posted ...". Bottom line is, POST is the preferred and correct way to pass data from browser to server.

您可以在URL中传递两个变量

$urlP = "print_one.php?uid=$from_date&uid2=$to_date";

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM