Forum Moderators: coopster
if (!$comment && $_COOKIE[$saveName])
$comment = $_COOKIE[$saveName]; <input type="hidden" name="commentVal" value="$comment"> I think the proper function to use is "htmlspecialchars" : [php.net...]
Be careful while using cookie to store user input, cookie length is limited to 4096 bytes (including the time stamp, domain and parameters). Usually, with contenteditable, when the user click on the submit button, a piece of javascript will retrieve the input, and store it into a hidden field.
// Get data if it's already been saved
// variable "saveName" is created on the parent page
var comment;
if (typeof(Storage) !== 'undefined')
comment = localStorage.getItem(saveName);
else
// getCookie is a function I wrote several years ago
comment = getCookie(saveName);
if (comment) {
// #comment is the contenteditable; if the browser doesn't support it then
// #commentText is a textarea backup
if ($('#comment').length)
$('#comment').html(comment);
else
$('#commentText').val(comment);
}
setInterval(function() {
var commentVal;
if ($('#comment').html())
commentVal = $('#comment').html();
else if ($('#commentText').val())
commentVal = $('#commentText').val();
if (commentVal) {
if (typeof(Storage) !== 'undefined')
localStorage.setItem(saveName, commentVal);
else
// setCookie is another function that I wrote a long time ago;
// the "1" sets it for 1 day
setCookie(saveName, commentVal, 1);
// #saved is on the parent page, just a DIV that says "Saved" and
// is set to style="display: none" by default
$('#saved').show()
.delay(750)
.fadeOut(1500);
}
}, 5000); localStorage.removeItem(saveName);