I have some checkboxes like this:
<input type="checkbox" name="regions[]" value="north-east" />North East<br />
<input type="checkbox" name="regions[]" value="north-west" />North West<br />
<input type="checkbox" name="regions[]" value="east-midlands" />East Midlands<br />
<input type="checkbox" name="regions[]" value="west-midlands" />West Midlands<br />
<input type="checkbox" name="regions[]" value="south-east" />South East<br />
<input type="submit" name="selectionsSubmit" value="Submit" />
Names and values can not be set differently, because I am using it for this php code:
if(isset($_POST['selectionsSubmit'])) {
$regions=$_POST["regions"];
$how_many=count($regions);
if($how_many>0)
{
$link=home_url('/') ."?tag=";
if($how_many!=12 && $how_many!=0)
{
for($i=0; $i<$how_many; $i++)
{
$link=$link ."+". $regions[$i];
}
}
wp_redirect($link);
}
else
{
echo 'You did not select anything.';
}}
It generates a tag link and redirects to that link. This is my first php code ever, and I should mention that I use wordpress.
Now I need a way to make selected checkboxes to be remembered for a session… until the user closes the site. I found many ways how to accomplish this, but I couldn’t make it work. I think that HTML5 sessionStorage might be of some use, but my lack of knowledge prevents me from finding the way.
Try php sessions, and if your values are not being tracked make sure to declare the session start. Try it without it first just in case wordpress has already started a session, which is likely. http://php.net/manual/en/features.sessions.php
EDIT:
@Chibuzu is right, if sessions isn’t working just use this code ABOVE where you are trying to access or set session variables