我希望在将表单发送到Paypal之前使用AJAX创建验证并更新数据库。
<form method="post" action="https://www.sandbox.paypal.com/cgi-bin/webscr" class="paypal-button" target="_top">
<div class="hide" id="errorBox"></div>
<input type="hidden" name="env" value="www.sandbox"><input type="hidden" name="notify_url" value="www.immortalinsurance.com">
<input type="hidden" name="tax" value="0">
<input type="hidden" name="shipping" value="0">
<input type="hidden" name="currency_code" value="AUD"><input type="hidden" name="amount" value="$15.00">
<input type="hidden" name="quantity" value="1">
<input type="hidden" name="item_name" value="Cover Yourself & a Friend"><input type="hidden" name="custom" value="">
<p class="paypal-group">
<label class="paypal-label" for="policy_name1">policy_name1
<input type="text" class="paypal-input" name="policy_name1">
</label></p>
<p class="paypal-group">
<label class="paypal-label" for="policy_name2">policy_name2
<input type="text" class="paypal-input" name="policy_name2">
</label></p>
<input type="hidden" name="button" value="buynow"><input type="hidden" name="cmd" value="_xclick">
<input type="hidden" name="business" value="xxx@gmail.com"><input type="hidden" name="bn" value="JavaScriptButton_buynow">
<button type="submit" class="paypal-button large">Buy Now</button>
</form>
1,确保字段不为空,否则出错。
2,确认价格符合$ row [&#39; price&#39;];别的错误。
如果以上陈述为真,则更新数据库并允许表格继续付款。
目前我只有:
$(document).on('submit', '.additem-form', function(event){
var self = this;
event.preventDefault();
$.ajax({
type: "POST",
url: "controller/initialstoring.php",
data: {
itemid: $('input[name=itemid]').val(),
amount: $('input[name=amount]').val()
},
success: function(data) {
$('input[name=custom]').val($lastid);
Continue with Usual Form Submit...
}
});
});
这是我的initialstoring.php:
<?php
include("../application/config/db_config.php");
$itemid = $_POST['itemid'];
$date = date('d-m-Y h:i:s');
$itemprice = $_POST['itemprice'];
$sql = "SELECT * FROM policies WHERE id = $itemid";
$stmt = $mysqli->query($sql);
$row = mysqli_fetch_assoc($stmt);
if ($itemprice == $row['price']) {
$insert_row = $mysqli->query("INSERT INTO purchases (name_on_policy, other_on_policy, dateofpurchase, status) VALUES ('$certname', '$othercertname', '$date', '$status')");
$lastid = $mysqli->insert_id;
} else {
echo "error";
}
?>
这是正确的方法吗? 也有理由在提交之前检查价格= $ row [price]吗?
我如何在ajax成功之后,在实际表单提交之前,添加到自定义变量?
由于