HTML:
<form action="https://live.sagepay.com/gateway/service/vspform-register.vsp" method="POST" id="sagepay_form">
<input type="hidden" name="navigate" value="" />
<input type="hidden" name="VPSProtocol" value="2.23">
<input type="hidden" name="TxType" value="PAYMENT">
<input type="hidden" name="Vendor" value="******************">
<input type="hidden" id= "Crypt" name="Crypt" value="">
<input id="payment_proceed" value="Proceed To Payment" class="mws-button green" type="button">
</form>
JS:
$("#payment_proceed").click(function() {
$.post('/includes/cart/ajax/sagepay.php', { //This script just echos the base64 "Crypt" string required by sagepay.
"cart_id": <?php echo $cart_id; ?>,
"title": $("#title").val(),
"first_name": $("#first_name").val(),
"last_name": $("#last_name").val(),
"telephone": $("#telephone").val(),
"email": $("#email").val(),
"line1": $("#line1").val(),
"line2": $("#line2").val(),
"line3": $("#line3").val(),
"town": $("#town").val(),
"county": $("#county").val(),
"postcode": $("#postcode").val()
},
function(crypt){
$("#Crypt").val(crypt); //The base64 "Crypt" string is inserted in to the hidden form field here.
alert($("#Crypt").val()); //I just put this here to make sure it had received the "Crypt" string.
$("#sagepay_form").submit(); //This doesn't work...
});
});
I have no idea why $("#sagepay_form").submit(); does not submit the form. My only guess is it's because the "action" url is a remote server. If this is the case, does anyone know how I can go about what I am trying to achieve?
Thanks, any help would be greatly appreciated.
Use
$("#sagepay_form").submit(function()
...instead of$("#payment_proceed").click(function()
.