【问题标题】:Radio buttons: PHP only passing "Other" value单选按钮:PHP 仅传递“其他”值
【发布时间】:2013-04-27 01:03:32
【问题描述】:

我已经借用了几个版本的 PHP(从这里和其他网站)将无线电字段集中的选定金额传递给电子商务网关,但无论我尝试了什么,它只会传递输入到我的“其他”字段(这是一个简单的文本框)。选择任何单选按钮后,我都会收到一条错误消息,表明该字段丢失或格式错误。这是我第一次使用 PHP,因此非常感谢一年级提供的任何帮助!虽然问题似乎与 if else if 语句有关,但我包含了整个 PHP,因为我并不真正了解 PHP 是如何工作的。谢谢。

    <?php 
$x_login = "HCO-ST.-T-902"; //  Hosted Payment Page ID. 
$transaction_key = "6~~xpvR~xMJXN_RkCc99"; // 

if(isset($_POST['amount'])) {
    if($_POST['amount'] == '5') {
        $x_amount = "5.00";
    } elseif($_POST['amount'] == '10') {
        $x_amount = "10.00";
    } elseif($_POST['amount'] == '25') {
        $x_amount = "25.00";
    } elseif($_POST['amount'] == '50') {
        $x_amount = "50.00";
    } elseif($_POST['amount'] == '100') {
        $x_amount = "100.00";
    } elseif($_POST['amount'] == '200') {
        $x_amount = "200.00";
    } elseif($_POST['amount'] == 'other') {
        $x_amount = $_POST['amount']; 
    }
}

$x_invoice_num = $_POST['invoice'];
$x_first_name = $_POST['x_first_name'];
$x_email = $_POST['x_email'];
$CardHoldersName= $_POST['CardHoldersName'];
$x_currency_code = "USD"; // Needs to agree with the currency of the payment page
srand(time()); // initialize random generator for x_fp_sequence
$x_fp_sequence = rand(1000, 100000) + 123456;
$x_fp_timestamp = time(); // needs to be in UTC. Make sure webserver produces UTC

// The values that contribute to x_fp_hash 
$hmac_data = $x_login . "^" . $x_fp_sequence . "^" . $x_fp_timestamp . "^" . $x_amount . "^" . $x_currency_code;
$x_fp_hash = hash_hmac('MD5', $hmac_data, $transaction_key);

echo ('<input type="hidden" name="x_login" value="' . $x_login . '">' );
echo ('<input type="hidden" name="x_amount" value="' . $x_amount . '">' );
echo ('<input type="hidden" name="x_fp_sequence" value="' . $x_fp_sequence . '">' );
echo ('<input type="hidden" name="x_fp_timestamp" value="' . $x_fp_timestamp . '">' );
echo ('<input type="hidden" name="x_fp_hash" value="' . $x_fp_hash . '" size="50">' );
echo ('<input type="hidden" name="x_currency_code" value="' . $x_currency_code . '">');
echo ('<input type="hidden" name="x_invoice_num" value="' . $x_invoice_num . '">');
echo ('<input type="hidden" name="x_first_name" value="' . $x_first_name . '">');
echo ('<input type="hidden" name="x_email" value="' . $x_email . '">');
?>
<input type="hidden" name="x_show_form" value="PAYMENT_FORM"/>

</form>

HTML

<fieldset name="amount">
<legend><h3>Amount**</h3></legend>
<hr class="hr">
<p style="margin:0">
<input name="amount" type="radio" value="5" checked="checked"> $5.00
<input name="amount" type="radio" value="10"> $10.00
<input name="amount" type="radio" value="25"> $25.00<br>
<input name="amount" type="radio" value="50"> $50.00
<input name="amount" type="radio" value="100"> $100.00
<input name="amount" type="radio" value="200"> $200.00
</p>
<input name="amount" type="radio" value="other"><span style="text-decoration: underline">Other Amount:  </span>
<input name="amount" type="text" style="width:100%">
</fieldset>

【问题讨论】:

  • 你的表单标签上的方法是什么?获取还是发布?
  • 看起来 post as by post value 是“其他”,但显然应该提及。
  • 由于我是菜鸟,所以无法回答问题,但想避免浪费大家的时间。所以这是我的解决方案:我不完全理解为什么,但解决方案是更改 HTML 中“其他”文本字段的“名称”,使其不包含在原始数组中。我将文本字段的名称更改为“otheramount”,但将“其他”单选按钮保留为数组的一部分。在 PHP 中,我更改了最后一个 elseif 语句以反映如果选择了“其他”单选按钮,则发布“其他金额”文本字段。
  • 这是 POST ......对不起,如果我理解它的价值/重要性,我会提供。
  • 我会在允许的时候发布修改后的 HTML 和 PHP(经过 8 小时的冷却期)。

标签: php post if-statement radio-button e-commerce


【解决方案1】:

更改您的最后一个文本字段名称。此名称不应与电台名称相同。

【讨论】:

    【解决方案2】:

    查看您的 html 代码:

    <fieldset name="amount">
    <legend><h3>Amount**</h3></legend>
    <hr class="hr">
    <p style="margin:0">
    <input name="amount" type="radio" value="5" checked="checked"> $5.00
    <input name="amount" type="radio" value="10"> $10.00
    <input name="amount" type="radio" value="25"> $25.00<br>
    <input name="amount" type="radio" value="50"> $50.00
    <input name="amount" type="radio" value="100"> $100.00
    <input name="amount" type="radio" value="200"> $200.00
    </p>
    <input name="amount" type="radio" value="other"><span style="text-decoration: underline">Other Amount:  </span>
    <input name="amount" type="text" style="width:100%">
    </fieldset>
    

    始终使用与前一个名称(数量)相同的最后一个 html 元素,在这种情况下,它是文本类型。 (它“覆盖”了之前的单选按钮)

    如果您更改文本字段的名称,您将在提交表单时获得所选单选按钮的值。

    尝试类似:

    <fieldset name="amount">
    <legend><h3>Amount**</h3></legend>
    <hr class="hr">
    <p style="margin:0">
    <input name="amount" type="radio" value="5" checked="checked"> $5.00
    <input name="amount" type="radio" value="10"> $10.00
    <input name="amount" type="radio" value="25"> $25.00<br>
    <input name="amount" type="radio" value="50"> $50.00
    <input name="amount" type="radio" value="100"> $100.00
    <input name="amount" type="radio" value="200"> $200.00
    </p>
    <input name="amount" type="radio" value="other"><span style="text-decoration: underline">Other Amount:  </span>
    <input name="otherAmount" type="text" style="width:100%">
    </fieldset>
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2015-10-04
      • 1970-01-01
      • 2021-04-14
      • 1970-01-01
      • 2013-12-24
      相关资源
      最近更新 更多