[Webinar] Streamline your web hosting managementRegister Today

x
?
Solved

Caching form data

Posted on 2008-01-28
5
Medium Priority
?
525 Views
Last Modified: 2013-12-13
I'm building a database website using PHP, Dreamweaver CS3, and MySQL. It's based pretty much on built on Dreamweaver's built in dynamic content templates. The pages follow CS3's style in that they post to themselves, and if they encounter a mysql error, then they die() with some relevant error message.

Problem is, after the page dies, if I hit the back button on the browser the form is blanked out. I can't go back to what I had previously typed in before hitting submit.

I've seen IE and FF "cache" the text you had typed in in previous forms in their history, so when you go back, the text is still there. Is there a way to turn this on on my page? Or does anyone know the reason why it isn't happening on mine?

Note: I'm not talking about restoring the values of the textboxes using PHP and the $_POST array when a page comes back with validation errors. I mean using the browser's back button and showing an older, cached form with text in it.
0
Comment
Question by:Frosty555
  • 2
  • 2
5 Comments
 
LVL 10

Accepted Solution

by:
adrpo earned 1000 total points
ID: 20766376

Hi,

I don't think you can base yourself on the cache for the forms.
If you go back you should rebuild the form data yourself to be
sure is still there.

As far as I know Internet Explorer doesn't save everything in the forms.
If you go back the forms will be empty. It has autocomplete, but that
doesn't work for the text areas.

Cheers,
za-k/
0
 
LVL 51

Assisted Solution

by:Steve Bink
Steve Bink earned 1000 total points
ID: 20766632
The form cache is a client feature, not a server feature.  You can, of course, pre-populate all your form controls, but you have no way of knowing what the user entered until the form is POSTed.

One alternative is to not let the page die() on a database error.  Instead, record the error and send an alert, and allow the page to continue rendering.  That way, should be able to retain the POST information.
0
 
LVL 31

Author Comment

by:Frosty555
ID: 20784150
I know it isn't a 100% surefire anything, I was just looking for some way to preserve the data in a textfield... without having to go into every form I've created and add code to repopulate the data from the $_POST array.

I'm sure I've seen this before, even on my own websites, so not some website where they could be repopulating the data from the $_POST array. IE would remember some ir not all of the text you entered into a form. It might be that it is when you hit submit and the page encounters some error, like a 404 error, as opposed to actually reaching a new page...

Is there any kind of solution that doesn't involve me re-coding all my pages to fill default values into the form?
0
 
LVL 51

Expert Comment

by:Steve Bink
ID: 20785605
As I said, the form cache is a client feature.  I'm sure you have seen it before, and I would suggest those sightings are examples of $_POST population, or your client retaining your entries.

The server has no way to know about the client's form cache, and would not have permission to access it if it did.  Unless the server receives $_POST data, or default data from another source (such as a database), you have no way to tap into previous entries.

Once you receive the $_POST data, you are left with programmatically inserting that data into the form controls.  
0
 
LVL 31

Author Comment

by:Frosty555
ID: 20804624
Damn. Well, I know how to do the $_POST repopulation, and I can remove the die() and replace it instead with an adding of data to an error property that I can display later in red in my form.

I just didn't want to edit every form I had made. Oh well.

Thanks everyone
0

Featured Post

Learn to develop an Android App

Want to increase your earning potential in 2018? Pad your resume with app building experience. Learn how with this hands-on course.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

This article shows the steps required to install WordPress on Azure. Web Apps, Mobile Apps, API Apps, or Functions, in Azure all these run in an App Service plan. WordPress is no exception and requires an App Service Plan and Database to install
In this article, I’ll talk about multi-threaded slave statistics printed in MySQL error log file.
Learn how to match and substitute tagged data using PHP regular expressions. Demonstrated on Windows 7, but also applies to other operating systems. Demonstrated technique applies to PHP (all versions) and Firefox, but very similar techniques will w…
The viewer will learn how to dynamically set the form action using jQuery.
Suggested Courses

591 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question