Mam poniższy kod który, który działa dobrze jednak mam problem w momencie przeładowania strony dane w dodanych polach input nie są zapisywane. Nie wiem czy obrobić to w jquery czy php. Proszę o pomoc.
$(document).ready(function () {
var getControl=getCookie("countControls1");
var max_fields_limit = 10;
var x = 0;
for(var i=1; i<=getControl; i++)
{
console.log(i);
addControls();
}
$('.add_more_button').click(function (e) { // Click event to add more fields
addControls();
});
function addControls()
{
console.log(x);
if (x < max_fields_limit)
{
x++;
setCookie("countControls1",x,100);
$('.input_fields_container').append('<div><input id="input1" placeholder="Imię i Nazwisko:" type="text" value=""/><a href="#" class="delete" >Usuń
</a></div>');
});
}
}
$('.input_fields_container').on("click", ".delete", function (e) { // User click on remove text links
$(this).parent('div').remove();
x--;
setCookie("countControls1",x,100);
});
function setCookie(cname,cvalue,exdays) {
var d = new Date();
d.setTime(d.getTime() + (exdays*24*60*60*1000));
var expires = "expires=" + d.toGMTString();
document.cookie = cname + "=" + cvalue + ";" + expires + ";path=/";
$("#div1").html("Add cookie = ",getCookie(cname));
}
function getCookie(cname)
{
console.clear();
var name = cname + "=";
var decodedCookie = decodeURIComponent(document.cookie);
var ca = decodedCookie.split(';');
console.log(ca);
for(var i = 0; i < ca.length; i++)
{
var c = ca[i];
while (c.charAt(0) == ' ')
{
c = c.substring(1);
}
if (c.indexOf(name) == 0)
{
console.log(c.substring(name.length, c.length));
return (c.substring(name.length, c.length));
}
}
return "";
}
});