I want to send fields data from a form to a file via AJAX and I found this solution online: http://techglimpse.com/pass-localstorage-data-php-ajax-jquery/
The only problem is that I have multiple fields instead of a single field and I want to save the output (localStorage) in an HTML (or any other format) file instead of showing it in an #output div.
How can I do that?
You can see my work that I've done till now here: Save form data using AJAX to PHP
And here's my HTML/JS code: http://jsbin.com/iSorEYu/1/edit & PHP code http://jsbin.com/OGIbEDuX/1/edit
PHP:
JS:
NOTE: Replace the file format of your_data file to html in the PHP code if you want your JSON data in HTML format.
You are overcomplocating things. The check for localStorage can be way simpler (other options). jQuery has a
serialze()
function that takes all form elements and serializes it. You can store them under "eloqua-fields" so you can find it again. No need to do some fancy random retrival.I'd like to add that not all of you code makes sense. Why use localstorage if you clear it every time the DOM is ready? Your validation does not abort the sending process if there are errors but I assume you just want to play around with stuff.
For the server part if you just want to store your data somewhere.