[英]Form submit not working with twitter bootstrap (PHP $_POST)
[英]PHP POST not Working on Submit FORM ["amount"]=> string(0) ""
我正在嘗試使用文本框並使用 JQuery 進行乘法運算,並嘗試將值保存到 PHP 變量中。
一個文本框是美元金額,我試圖將其乘以當地貨幣匯率。
這是代碼 HTML
<form action="#" method="POST" id="easyPayStartForm">
<input name="storeId" value="
<?php echo $storeId; ?>" hidden="true" />
<input name="amount" value="
<?php echo $amount; ?>" hidden="true" />
<input name="postBackURL" value="
<?php echo $postBackURL; ?>" hidden="true" />
<input name="orderRefNum" value="
<?php echo $orderRefNum; ?>" hidden="true" />
<input type="hidden" name="expiryDate" value="
<?php echo $expiryDate; ?>">
<input type="hidden" name="autoRedirect" value="
<?php echo $autoRedirect; ?>">
<input type="hidden" name="paymentMethod" value="
<?php echo $paymentMethod; ?>">
<input type="hidden" name="emailAddr" value="
<?php echo $emailAddr; ?>">
<input type="hidden" name="mobileNum" value="
<?php echo $mobileNum; ?>">
<input type="hidden" name="merchantHashedReq" value="
<?php echo $hashRequest; ?>">
<input type="text" id="firstNumber" name="text22" class="form-control ml-1" placeholder="0">
<input type="text" name="newtxt" id="result1" class="amount">
<button type="submit" id="sbt" class="btn btn-primary button">Submit</button>
</form>
JQuery
$(document).ready(function() {
var timestamp = new Date().getTime();
$('#orderref').val(timestamp);
$("#firstNumber").keyup(function() {
is also possible instead of "keyup()"
var input_value = parseFloat($("#firstNumber").val());
if (!isNaN(input_value)) { // the input is a number
var newnum = (input_value * 182);
$("#result").text(newnum.toFixed(1));
//$("#amount").val(newnum.toFixed(1));
$("#result1").val(newnum.toFixed(1));
} else { // the input wasn't a number
$("#result").val("not a number?");
}
});
});
PHP:
ob_start();
ini_set('display_errors', 1);
error_reporting(E_ALL);
var_dump($_POST);
$hashRequest = '';
$hashKey = 'abcede'; // generated from easypay account
$storeId="1234";
$int = filter_input(INPUT_POST, 'text22', FILTER_VALIDATE_INT);
$amount= $int ;
DUMP :
array(13) { ["storeId"]=> string(4) "123" ["amount"]=> string(0) "" ["postBackURL"]=> string(44) "abvbc" ["orderRefNum"]=> string(10) "1640307967" ["expiryDate"]=> string(138) "
嘗試在此處獲取文本框值但無法顯示字符串而不是值和 integer
["amount"]=> string(0) ""
謝謝
這條線讓你絆倒:
filter_input(INPUT_POST, 'text22', FILTER_VALIDATE_INT)
查看您的變量,我認為您想要 FILTER_VALIDATE_FLOAT - 但即使您仍然會遇到同樣的問題。 當過濾器不成功時,filter_input 返回 false 或 null,那么為什么不將值強制為您想要的類型
$amount = floatVal($_POST['newtxt'])
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.