从php中的文本框中获取值

时间:2011-04-19 12:27:26

标签: php textbox

我正在尝试创建一个捐赠页面。孔页是php,

有一个文本框,其中包含应通过隐藏输入发送的金额值,并将URL发送到支付网关。我已经尝试了很多次但是没有用。我仍然是初学者,请任何人帮我修复我的代码

   <div class="donate">
   <?php
        $amount = $_REQUEST['amount'];
        $txtCurrency = 840;
        $txtAmount   = number_format($amount, 2, '.', '');
        echo $amount;       
        $key     = "TEST";
                    $txthttp     = "http://test.com/you.php";

    ?> 
    <form action="payment.php" name="form1">
        <input type="text" id="amount">
        <input type="submit">
            <input type="hidden" name="txtAmount" value="<?= $txtAmount; ?>">
            <input type="hidden" name="txthttp" value="<?= $txthttp; ?>">
            <input type="hidden" name="signature" value="<?= $key; ?>">
    </form>
   </div>

2 个答案:

答案 0 :(得分:3)

一般情况下,如果可以使用$_REQUEST$_GET,则应避免使用$_POST$_REQUEST允许通过HTTP GET或POST设置变量,这可能会带来安全风险,因为您的网站可能会使用其中一个。话虽如此,这就是我要做的事情:

  1. method="post"添加到您的form代码。
  2. 通过查看$_POST['txtAmount']$_POST['txthttp']
  3. 来访问输入元素

    通常,您可以通过以下方式查看POST中设置的所有变量:

    var_dump($_POST);

答案 1 :(得分:0)

您可以使用$ _POST ['txtAmount'],$ _POST ['txthttp'],$ _POST ['signature']从payment.php访问这些值。如何处理它们将取决于您的代码。我看到你使用了$ _REQUEST数组,它可以工作,但我相信它是更好的形式,具体使用$ _POST数组。