1

I've been having some issues with this. All I want to do is save whatever the user types into the text input when they click submit even on refresh of page.

I have already tried localStorage, but that won't work because I want it to work with any browser. As in I can save the data on chrome, and go to IE and see that the form input values are still the same.

I have tried sending the form data via action POST, but how can I get that to KEEP the data after refresh? Right now I have it so it sends the data to a new page (that looks exactly the same) and can post the saved values in the input, but it doesn't stay there on refresh.

I also tried something called "sisyphus" but I couldn't even get that to work even though I already have jQuery installed. I used the exact example someone gave me, so if anyone can tell me why that didn't work, this might be the best solution.

Please help!

asked Apr 26, 2013 at 9:38
4
  • You need a server file/database Commented Apr 26, 2013 at 9:41
  • Try using session cookies. Commented Apr 26, 2013 at 9:42
  • What's your IE version....?? Commented Apr 26, 2013 at 9:42
  • Wouldn't cookies only last for a certain amount of time? Commented Apr 26, 2013 at 9:45

4 Answers 4

1

Since you want the data to persist across browsers/sessions, it sounds like you're going to need some kind of way to store that information, like a database or even a writeable file will do.

But secondly, you'll need a way to differentiate between users (some kind of login system), unless you want everyone who visits the form to see the inputs that the original person entered (like a google doc).

answered Apr 26, 2013 at 9:45
Sign up to request clarification or add additional context in comments.

4 Comments

Can you further explain what you meant by using a writeable file? How would this work? And no need to worry about permissions between users for now.
Well, if you want the functionality of a database without the overhead, something like SQLite might do well for you. Or you could literally just write your data to a text file (see php fopen and fwrite for more info)
Well as I said I already have a second file that the form saves to. Its just a second php file that has the same content. Would I be able to just do this like you said using my second file?
Well, strictly speaking, I don't know of 'best practices' way to accomodate your scenario. There isn't usually a good reason to create two separate php pages with duplicate content. If the pages are identical, I'd recommend only having one page, that submits to itself and saves the data to some kind of storage device. The method of retrieving the data is completely dependent on the storage you choose.
1

Start with using databases: http://www.freewebmasterhelp.com/tutorials/phpmysql/1

BEWARE: mysql_* functions in PHP are deprecated, use alternatives instead (you can find them on google)

I'm not sure if this is the answer to your question, your question was a bit unclear. I hope it helps!

answered Apr 26, 2013 at 9:43

6 Comments

I know I could technically use a database for this, but there has to be an easier way to store a couple of form inputs permanently without using a database.
From my knowledge, databases are the easiest and most secure way. An alternative is to write the result to a file, but that brings a whole lot of complications regarding retrieval of your data.
Someone else mentioned doing this with a writeable file. Would you mind going further in-depth with this? As in, okay, the user saves and it posts the data to the extra page. How would I get the data back from the page to display on the first page with the form inputs?
html5rocks.com/en/tutorials/file/filesystem Check this link to write into a file and of course this is also html5 which is accepted only in IE8+ ... What's your IE version...??
If I understand you correctly, you want to retrieve the data the user entered in a form and display it again on the original page with the form and you don't want to use a database. If so, you might want to use XML (this might be a good answer: wiki.answers.com/Q/How_retrieve_xml_data_using_php) because you'll receive multiple POST variables in your PHP, and it'll be easy to retrieve with the proper XML parser.
|
1

If you want it to be for IE8+,then you can do it using localStorage with proper doctype

<!DOCTYPE html>
answered Apr 26, 2013 at 9:47

Comments

1

1.Store that value in session and retrieve and display it.
2.cookies

answered Apr 26, 2013 at 9:50

3 Comments

Don't both of these only last for a certain amount of time though?
cookie. time can be set. session only last until the user is logged in
Thanks for the info. Is it possible to set a permanent cookie?

Your Answer

Draft saved
Draft discarded

Sign up or log in

Sign up using Google
Sign up using Email and Password

Post as a guest

Required, but never shown

Post as a guest

Required, but never shown

By clicking "Post Your Answer", you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.