I have a page where I enter a name and check a series of checkboxes. The result is saved to a server-side text file using PHP.
I access the data associated with any particular name by using the following PHP:
<?php
$search = $_GET["name"];
$comments = file_get_contents('comments.txt');
$array = explode("~",$comments);
echo "<html>";
foreach($array as $item){
if(strstr($item, $search)){
echo $item;
} }
?>
I would like to recall this data at a future date. When I select a name again, the associated checkboxes would somehow change in css style (to remind me they were checked in a previous session).
<nobr><input type="checkbox" name="comment" id="AAA" value="Example text. " onclick="createOrder()"><label for="AAA" onclick="createOrder()" title=
"Example text.">
example </label></nobr><br>
My theoretical solution: On the press of button or some such event, the PHP would search for the selected name, search for AAA in association with that name, and (if found) change the color of label for AAA.
I'm not sure cookies would be appropriate here. The simple PHP above just echos the data to a page. Is my suggested method even possible?
To elaborate:
My goal is to enter a name and check boxes. That data is stored in a text file with all other names and checkbox data. Perhaps as such:
John Smith AAA FFF RRR
Jill Jones BBB RRR ZZZ
On a future session, when John Smith is entered again, the labels for checkboxes with ID AAA, FFF, and RRR will change color to remind me that they were checked last time.
The easiest way is to use the php session variable to store temporary data.
session_start();
$_SESSION[$search] = $checkboxStates;
The session variable needs to be initialized and can be used across multiple user requests. Typically session relies on cookie so data will be lost when the browser clear the cookie.