PHP/[removed] Remembering state of form/form field

2019-06-04 20:31发布

In this question, I found out how to dynamically add form fields.

Now, how can I set a cookie to remember the amount of form fields that were generated, and their content?

eg. First visit, user types this:

Input one
Input two
Input three

Then he/she visits the page again. There are 3 form fields, containg Input one, Input two and Input 3.

Is this possible using a server/client side solution?

Thanks a lot,

Harley

2条回答
Animai°情兽
2楼-- · 2019-06-04 21:12

there is a useful plugin of jquery "Jquery Populate" you can store your json in cookie/session and use it to fill your forms.

查看更多
劫难
3楼-- · 2019-06-04 21:20

assuming that the input textfield class is "textfield1" -

This snippet will capture the data into a cookie when the value is modified

  $(".textfield1").change(function() {
       $.cookie("textfield1", $(".textfield1").val(), {expires: 7});
  });

This snippet will read the cookie data and populate the field on page load -

  $(".textfield1").val( $.cookie("textfield1") );

Put both these snippets inside $(document).ready(function(){ }); and you are good to go !

查看更多
登录 后发表回答