Php dynamic forms not caching form fields

Php dynamic forms not caching form fields

Form Fields are not Populated after Pressing Back Button

1. Create the file: cache.html

2. chmod 666 cache.html

3. Add this code to the top of your php form page

$cachefile = ‘cache.html’;

$cachetime = 4 * 60;

// Serve from the cache if it is younger than $cachetime

if (file_exists($cachefile) && time() – $cachetime < filemtime($cachefile)) {

include($cachefile);

echo “<!– Cached copy, generated “.date(‘H:i’, filemtime($cachefile)).” –>\n”;

exit;

}

ob_start(); // Start the output buffer

/* Heres where you put your page content */

// Cache the contents to a file

$cached = fopen($cacheFile, ‘w’);

fwrite($cached, ob_get_contents());

fclose($cached);

ob_end_flush(); // Send the output to the browser

 

 

4. Have your text boxes echo the $_POST value as per the example below:

<input type=”text” name=”Field” required value=”<?php echo $_POST[“Field”]; ?>”>