在当前代码中,我在同一个php页面(delivery.php)上有POST和GET方法,如下所示。 我想要实现的是通过按下按钮(转到付款页面)将以下项目1-5传递到下一页(payment.php)。
ITEM1;要求(这是来自上一页)
ITEM2;名称(用户输入)
项目3; shippingfee(在代码中以span标签显示,这是通过GET方法从shipping.php返回的值)
ITEM4;地址(用户输入)
ITEM5;电子邮件(用户输入)
我怎样才能做到这一点?
delivery.php
<?php
$request = $_POST['request'];
?>
<html>
....
<form name="aaa" method="POST" action="payment.php">
<input name="name"></input>
</form>
<form name="bbb" method="GET" action="shipping.php">
<select id="country" name="countryshipping">
<option value="null" select="selected">default</option>
<option value="1">1</option>
<option value="2">2</option>
</select>
</form>
<form name="ccc" method="POST" action="payment.php">
<input name="address"></input>
<input name="email"></input>
</form>
....
<div>
<span id="shippingfee"></span>
</div>
....
<form ????????>
<button type="submit">Go to payment page</button>
</form>
....
解决方案
我可以设法实现我想做的事情。分享我的代码:
delivery.php
<?php
$request = $_POST['request'];
?>
<html>
....
<form name="aaa" method="POST" action="payment.php">
<input name="name"></input>
<select id="country" name="countryshipping">
<option value="null" select="selected">default</option>
<option value="1">1</option>
<option value="2">2</option>
</select>
<input name="address"></input>
<input name="email"></input>
</form>
....
<div>
<input type="hidden" name="shippingfee" id="shippingfee2"><span id="shippingfee"></span>
</div>
....
<button type="submit">Go to payment page</button>
</form>
....
Payment.php
<?php
$name = $_POST['name'];
$country = $_POST['countryshipping'];
$address = $_POST['address'];
$email = $_POST['email'];
$shippingfee = $_POST['shippingfee'];
?>
除了上面的代码,我在jQuery中添加了一行
document.getElementById("totalfees2").value = value; // "this value is the same value which is stored in id="shippingfee""
答案 0 :(得分:2)
$ _ REQUEST将提供所有的get和post vars。
echo $_REQUEST['baz']; // "qux"
echo $_REQUEST['foo']; // "baz"
答案 1 :(得分:1)
<form action="script.php?foo=bar" method="post">
<input type="text" name="baz" value="qux">
<input type="submit">
</form>
<?php
echo $_POST['baz']; // "qux"
echo $_GET['foo']; // "baz"
请注意,反过来不起作用。您不能拥有get
方法表单,也可以提交POST数据。