簡體   English   中英

單選按鈕:PHP僅傳遞“ Other”值

[英]Radio buttons: PHP only passing “Other” value

我借用了多個版本的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>

更改您的最后一個文本字段名稱。 此名稱不應與無線電名稱相同。

查看您的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元素,在這種情況下,它是text類型的。 (它“替代”了先前的單選按鈕)

如果更改文本字段的名稱,則在提交表單時將獲得所選單選按鈕的值。

嘗試類似:

<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>

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM