Last active
June 14, 2016 08:58
-
-
Save olivmonnier/ad64ff886a36eafeb72c to your computer and use it in GitHub Desktop.
Création d'un cookie sur les formulaires
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<form id="form"> | |
<input type="text" name="first_name"/> | |
<input type="text" name="last_name"/> | |
<input type="email" name="email"/> | |
<input type="submit" value="Send"/> | |
</form> | |
<script> | |
var cookieForm = new FormCookie('form', 365); | |
//Save or Update cookie 'form' | |
cookieForm.formDatas = $('#form').serializeArray(); | |
cookieForm.exeptionFields = ['first_name']; | |
(cookieForm.exist()) ? cookieForm.update() : cookieForm.create(); | |
//Put datas cookie in form | |
var cookieDatas = cookieForm.read(); | |
if(cookieForm.exist()) { | |
for(var x = 0; x < cookieDatas.length; x++) { | |
$('[name="' + cookieDatas[x].name + '"]').val(cookieDatas[x].value).change(); | |
} | |
} | |
</script> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment