I'm new to wordpress and I have a question How can I save the checkbox values on all wordpress pages for the current user? For all other users, the code does not apply. I have a code <form method="POST"> Option One: <input type="checkbox" name="check1" value="1" <?php if(isset($_POST['check1'])) echo 'checked="checked"'; ?> /> Option Two: <input type="checkbox" name="check2" value="2" <?php if(isset($_POST['check2'])) echo 'checked="checked"'; ?> /> <br> <input type="submit" value="Submit" /> </form>
`<?php
if(isset($_POST['check1'])){
echo '22222';
}
elseif(isset($_POST['check2'])){
echo '3455';
}
?>`
but when you go to another page, everything is reset
how do i fix it? Tell me please
You might work with php session or javascript localstorage.
Working with tabs will be a right solution, or else, storage right here
session_start();
if(isset($_POST['check'])){
$_SESSION['customer_values']['check_1'] = "VALUE1";
}
if(isset($_POST['check2'])){
$_SESSION['customer_values']['check_2'] = "VALUE2";
}
I do not know why but the code in the comments is buggy Therefore, I will write it to him here
<form method="POST">
Option One: <input type="checkbox" name="check1" value="1" <?php if ( isset($_SESSION
['customer_values'] ['check1'] ) ) echo 'checked = "checked" '; ?> />
Option Two: <input type="checkbox" name="check2" value="1" <?php if ( isset
($_SESSION ['customer_values'] ['check2'] ) ) echo 'checked = "checked" '; ?> />
<br>
<input type="submit" value="Submit" />
</form>
<?php
session_start();
if(isset($_POST['check1'])){
$_SESSION['customer_values']['check1'] = "VALUE1";
}
if(isset($_POST['check2'])){
$_SESSION['customer_values']['check2'] = "VALUE2";
}
?>
You had this code, if yes then for some reason it does not work