【问题标题】:How to get value from HTML form in PHP and use on the same page如何在 PHP 中从 HTML 表单中获取值并在同一页面上使用
【发布时间】:2018-05-06 15:21:42
【问题描述】:

我正在为电子商务实践网站使用 PayPal 按钮脚本。 PayPal 代码是我在 PHP 中回显的 HTML 表单。我需要从输入的表单中获取用于更新数据库的值。如何从提交的表单中获取 PHP 中的金额、数量和价值表单字段?

贝宝表格

$paypalButton = '<form action="https://www.sandbox.paypal.com/cgi-bin/webscr" method="post">
<input type="hidden" name="amount" value=' .$value .'>

<div class="form-group row col-xs-3 col-md-2">
    <label class="control-label" for="usr">Quantity</label>
    <input type="number" class="form-control"
    name="quantity" value=' .$quantity .' min="1" max="10">                 
</div>

<input type="hidden" name="cmd" value="_xclick">
<input type="hidden" name="business" value=' .$paymentId .'>
<input type="hidden" name="item_name" value=' .$itemName .'>
<input type="hidden" name="currency_code" value=GBP>
<input type="hidden" name="UseSandbox" value="true">
<input type="hidden" name="return" value=' .$returnURL .'>
<input type="hidden" name="cancel_return" value=' .$cancelURL .'>

<div class="form-group row col-xs-12 col-md-12">
    <label class="control-label" for="usr"></label>
    <input type="image" align="centre" src="http://www.paypal.com/en_AU/i/btn/x-click-but01.gif" name="submit" alt="Make payments with PayPal - its fast, free and secure!">
</div>

</form>';

【问题讨论】:

  • 通过 PHP 提交表单。您将获得您在表单中提交的值的超全局 $_POST[] 数组。您可以通过执行 var_dump($_POST['quantity']); 来转储这些值。这将从$_POST[] 超全局返回来自该输入字段的数据。这些值来自表单的 name 属性。因此,如果您想获取任何值,只需使用名称值调用 POST。

标签: php html forms paypal


【解决方案1】:

你应该这样做

$variable = $_POST["anotherVar"];

例子:

$paymentID = $_POST["paymentId"];

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2020-05-04
    • 1970-01-01
    • 1970-01-01
    • 2019-02-25
    • 1970-01-01
    • 2012-07-19
    • 2021-11-06
    • 2023-03-13
    相关资源
    最近更新 更多