php - 如何在提交到其他网站后保留表单值?

时间:2014-08-21 09:43:54

标签: payment-gateway

我正在制作支付网关并将其提交给itransact.com。

如何在提交itransact后保留这些值?如果值有错误,则客户返回表单并且所有值都消失。

1 个答案:

答案 0 :(得分:1)

您可以使用JavaScript将所需的值推送到Cookie之前,作为表单发送。例如:

<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>

现在JavaScript方面:

<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>

您可以使用此示例获取有关设置Cookie的更多信息:http://www.the-art-of-web.com/javascript/setcookie/