Store form in localstorage, retrieve it later for submit

In a wordpress website I want that when someone fills a product form (select attributes etc) and clicks buy now, if is not logged in then he is redirected to login form. On succesfull login I want to get the submitted form contents from localstorage, fill the form and then submit the form automatically.

Is that possible?

I found that I can store the submitted form like this (but how I can refill the form automatically?):

$(document).ready(function()    {  
    $('form').submit(function(e) {    
        e.preventDefault();
        var formFields = $(this).serialize();
        localStorage.setItem('myForm', formFields);    
        //data = localStorage.getItem('myForm');  //retrieve it later
     });
});