By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
448,948 Members | 1,080 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 448,948 IT Pros & Developers. It's quick & easy.

Retain checkbox value

P: 1
My question is that first i need to create the checkboxes which i have already done and then when i set the value of any of the checkboxes as checked, it should be saved in a session after clicking on the submit button and after refresh page also.. so that next user could see the selected checkbox
Mar 6 '12 #1
Share this Question
Share on Google+
1 Reply

P: 77
Expand|Select|Wrap|Line Numbers
  1. <?php
  2. if(isset($_POST['checkboxname'])) {
    $_SESSION['checkboxvalues'] = json_encode($_POST['checkboxname');
  4. else if(isset($_SESSION['checkboxvalues'])) {
    $checkboxValues = json_decode($_SESSION['checkboxvalues']);
    foreach($checkboxValues as $value) {
    //iterate through, echoing checkboxes and setting checked to "checked" based on whether the array is checked
  6. else {
    //display fresh checkboxes
  7. ?>
Mar 25 '12 #2

Post your reply

Sign in to post your reply or Sign up for a free account.