Вот example.
Все, что вам нужно, это JQuery и cookie plugin
Имейте в виду, там уже несколько изменений в HTML коде.
$(document).on('submit', '#myForm', function() {
// serialize our form (get string containing field names and values)
dataString = $(this).serialize();
// set new cookie
$.cookie('formCookie', dataString);
return false;
});
$(document).on('click', '#getCookie', function() {
// get serialized string from cookie
cookieData = $.cookie('formCookie');
// if cookie exists continue
if (cookieData != null) {
// split cookieData string into an array of fields and their values
cookieArray = cookieData.split('&');
// go through each field and split it too to get field name and it's value
$.each(cookieArray, function(k, v) {
field = v.split('=');
// populate field with data
$('#myForm [name="'+field[0]+'"]').val(field[1]);
});
}
return false;
});
Сохранение значений формы в файле cookie не имеет большого смысла. Какова ваша конечная цель? Возможно, вам лучше будет хранить их в сеансе. – Corbin