我已經借了(在這裏和其他網站)PHP的幾個版本的選定量的無線電字段集傳遞到電子商務門戶,但不管是什麼我都試過了,它只會通過輸入到我的「其他」字段(這是一個簡單的文本框)的金額。選中任何一個單選按鈕後,出現一個錯誤信息,指出該字段丟失或格式錯誤。這是我第一次使用PHP,因此非常感謝在一年級提供的任何幫助!雖然這個問題似乎與if語句相關,但我包含了整個PHP,因爲我不太瞭解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>
什麼是你的表單標籤的方法是什麼? GET還是POST? – Chris 2013-05-02 18:32:53
看起來像郵政價值是作爲「其他」,但顯然應該提到。 – 2013-05-02 18:40:28
由於我是新手,我無法回答這個問題,但是想避免浪費每個人的時間。因此,這裏是我的解決方案: 我完全不明白爲什麼,但解決的辦法是改變HTML中的「其他」文本字段的「名」,因此,它不包括作爲原始陣列的一部分。我將文本字段的名稱更改爲「其他」,但將「其他」單選按鈕作爲數組的一部分。 在PHP中,我更改了最後一個elseif語句,以反映如果選擇了「other」單選按鈕,然後POST「其他」文本字段。 – 2013-05-02 18:52:44