Reputation: 897
I'm making a payment gateway and its submitting to itransact.com.
How to keep the values after submitting to itransact? If the values have an error to the itransact the customer back to the form and all values are gone.
Upvotes: 0
Views: 255
Reputation: 2752
You can use JavaScript to push needed values to cookies before, as form send. For example:
<form onsubmit="return storeValues(this);" action="" method="POST" name="userForm">
<input type="text" value="" name="firstname">
<input type="text" value="" name="lastname">
<input type="submit" value="Send request">
</form>
Now JavaScript side:
<script>
/* Set cookies to browser */
function storeValues(form)
{
setCookie("firstname", form.firstname.value);
setCookie("lastname", form.lastname.value);
return true;
}
var today = new Date();
var expiry = new Date(today.getTime() + 30 * 24 * 3600 * 1000); // today + 30 days
function setCookie(name, value)
{
document.cookie=name + "=" + escape(value) + "; path=/; expires=" + expiry.toGMTString();
}
/* --Set cookies to browser */
function getCookie(name) {
var value = "; " + document.cookie;
var parts = value.split("; " + name + "=");
if (parts.length == 2) return parts.pop().split(";").shift();
}
/* Loading cookie values into the form */
if(firstname = getCookie("firstname")) document.userForm.firstname.value = firstname;
if(lastname = getCookie("lastname")) document.userForm.lastname.value = lastname;
/* --Loading cookie values into the form */
</script>
You can get more info about setting cookies using this example: http://www.the-art-of-web.com/javascript/setcookie/
Upvotes: 1