Я храню данные о клиентах, которые они ввели в переменные сеанса, которые применяются к соответствующим html-полям, если клиент перенаправляется со страницы оформления заказа.Это было реализовано из-за ошибки PayPal (место, где я работаю, как эта странная установка PayPal, которая действует как последний шаг после ввода всей вашей информации).Исправление, казалось, работало в течение довольно долгого времени, но теперь, по-видимому, в последние несколько недель люди перенаправляются обратно из PayPal, а соответствующие поля теперь пустые.
Ниже приведен скрипт, который я использую для храненияпеременные сеанса.
<script>
// Run on page load
window.onload = function() {
// If sessionStorage is storing default values (ex. name), exit the function and do not restore data
if (sessionStorage.getItem('billing_firstname') == "billing_firstname") {
return;
}
// If values are not blank, restore them to the fields
var billing_firstname = sessionStorage.getItem('billing_firstname');
if (billing_firstname !== null) $('#billing_firstname').val(billing_firstname);
var billing_lastname= sessionStorage.getItem('billing_lastname');
if (billing_lastname !== null) $('#billing_lastname').val(billing_lastname);
var billing_company= sessionStorage.getItem('billing_company');
if (billing_company !== null) $('#billing_company').val(billing_company);
var billing_state= sessionStorage.getItem('billing_state');
if (billing_state !== null) $('#billing_state').val(billing_state);
var billing_country= sessionStorage.getItem('billing_country');
if (billing_country !== null) $('#billing_country').val(billing_country);
var billing_address= sessionStorage.getItem('billing_address');
if (billing_address !== null) $('#billing_address').val(billing_address);
var billing_address2= sessionStorage.getItem('billing_address2');
if (billing_address2 !== null) $('#billing_address2').val(billing_address2);
var billing_city= sessionStorage.getItem('billing_city');
if (billing_city !== null) $('#billing_city').val(billing_city);
var billing_zip= sessionStorage.getItem('billing_zip');
if (billing_zip !== null) $('#billing_zip').val(billing_zip);
var billing_phone= sessionStorage.getItem('billing_phone');
if (billing_phone !== null) $('#billing_phone').val(billing_phone);
}
// Before refreshing the page, save the form data to sessionStorage
window.onbeforeunload = function() {
sessionStorage.setItem("billing_firstname", $('#billing_firstname').val());
sessionStorage.setItem("billing_lastname",$('#billing_lastname').val());
sessionStorage.setItem("billing_company",$('#billing_company').val());
sessionStorage.setItem("billing_state", $('#billing_state').val());
sessionStorage.setItem("billing_country", $('#billing_country').val());
sessionStorage.setItem("billing_address",$('#billing_address').val());
sessionStorage.setItem("billing_address2",$('#billing_address2').val())
sessionStorage.setItem("billing_city",$('#billing_city').val());
sessionStorage.setItem("billing_zip",$('#billing_zip').val());
sessionStorage.setItem("billing_phone",$('#billing_phone').val());
}
</script>
<script>
// Run on page load
window.onload = function() {
// If sessionStorage is storing default values (ex. name), exit the function and do not restore data
if (sessionStorage.getItem('shipping_firstname') == "shipping_firstname") {
return;
}
// If values are not blank, restore them to the fields
var shipping_firstname = sessionStorage.getItem('shipping_firstname');
if (shipping_firstname !== null) $('#shipping_firstname').val(shipping_firstname);
var shipping_lastname= sessionStorage.getItem('shipping_lastname');
if (shipping_lastname !== null) $('#shipping_lastname').val(shipping_lastname);
var shipping_company= sessionStorage.getItem('shipping_company');
if (shipping_company !== null) $('#shipping_company').val(shipping_company);
var shipping_state= sessionStorage.getItem('shipping_state');
if (shipping_state !== null) $('#shipping_state').val(shipping_state);
var shipping_country= sessionStorage.getItem('shipping_country');
if (shipping_country !== null) $('#shipping_country').val(shipping_country);
var shipping_address= sessionStorage.getItem('shipping_address');
if (shipping_address !== null) $('#shipping_address').val(shipping_address);
var shipping_address2= sessionStorage.getItem('shipping_address2');
if (shipping_address2 !== null) $('#shipping_address2').val(shipping_address2);
var shipping_city= sessionStorage.getItem('shipping_city');
if (shipping_city !== null) $('#shipping_city').val(shipping_city);
var shipping_zip= sessionStorage.getItem('shipping_zip');
if (shipping_zip !== null) $('#shipping_zip').val(shipping_zip);
var shipping_phone= sessionStorage.getItem('shipping_phone');
if (shipping_phone !== null) $('#shipping_phone').val(shipping_phone);
//Billing
// If values are not blank, restore them to the fields
var billing_firstname = sessionStorage.getItem('billing_firstname');
if (billing_firstname !== null) $('#billing_firstname').val(billing_firstname);
var billing_lastname= sessionStorage.getItem('billing_lastname');
if (billing_lastname !== null) $('#billing_lastname').val(billing_lastname);
var billing_company= sessionStorage.getItem('billing_company');
if (billing_company !== null) $('#billing_company').val(billing_company);
var billing_state= sessionStorage.getItem('billing_state');
if (billing_state !== null) $('#billing_state').val(billing_state);
var billing_country= sessionStorage.getItem('billing_country');
if (billing_country !== null) $('#billing_country').val(billing_country);
var billing_address= sessionStorage.getItem('billing_address');
if (billing_address !== null) $('#billing_address').val(billing_address);
var billing_address2= sessionStorage.getItem('billing_address2');
if (billing_address2 !== null) $('#billing_address2').val(billing_address2);
var billing_city= sessionStorage.getItem('billing_city');
if (billing_city !== null) $('#billing_city').val(billing_city);
var billing_zip= sessionStorage.getItem('billing_zip');
if (billing_zip !== null) $('#billing_zip').val(billing_zip);
var billing_phone= sessionStorage.getItem('billing_phone');
if (billing_phone !== null) $('#billing_phone').val(billing_phone);
}
// Before refreshing the page, save the form data to sessionStorage
window.onbeforeunload = function() {
sessionStorage.setItem("shipping_firstname", $('#shipping_firstname').val());
sessionStorage.setItem("shipping_lastname",$('#shipping_lastname').val());
sessionStorage.setItem("shipping_company",$('#shipping_company').val());
sessionStorage.setItem("shipping_state", $('#shipping_state').val());
sessionStorage.setItem("shipping_country", $('#shipping_country').val());
sessionStorage.setItem("shipping_address",$('#shipping_address').val());
sessionStorage.setItem("shipping_address2",$('#shipping_address2').val())
sessionStorage.setItem("shipping_city",$('#shipping_city').val());
sessionStorage.setItem("shipping_zip",$('#shipping_zip').val());
sessionStorage.setItem("shipping_phone",$('#shipping_phone').val());
//billing
sessionStorage.setItem("billing_firstname", $('#billing_firstname').val());
sessionStorage.setItem("billing_lastname",$('#billing_lastname').val());
sessionStorage.setItem("billing_company",$('#billing_company').val());
sessionStorage.setItem("billing_state", $('#billing_state').val());
sessionStorage.setItem("billing_country", $('#billing_country').val());
sessionStorage.setItem("billing_address",$('#billing_address').val());
sessionStorage.setItem("billing_address2",$('#billing_address2').val())
sessionStorage.setItem("billing_city",$('#billing_city').val());
sessionStorage.setItem("billing_zip",$('#billing_zip').val());
sessionStorage.setItem("billing_phone",$('#billing_phone').val());
}
</script>