SHARE
TWEET

Checkbox selected

a guest Oct 23rd, 2019 84 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. <?php
  2. session_start();
  3.  
  4. $scelte = [
  5.     'Scelta1',
  6.     'Scelta2',
  7.     'Scelta3',
  8.     'Scelta4'
  9. ];
  10. ?>
  11. <html>
  12.     <head></head>
  13.     <body>
  14.         <form method="post">
  15.             <?php foreach($scelte as $scelta):?>
  16.             <?php $checked = isset($_SESSION['check']) && in_array($scelta, $_SESSION['check']) ? 'checked' : ''?>
  17.             <input type="checkbox" name="check[]" value="<?php echo $scelta;?>" <?php echo $checked;?>> <?php echo $scelta;?>
  18.             <?php endforeach;?>
  19.             <input type="submit" name="ok" value="Fai la tua scelta" />
  20.         </form>
  21.         <?php
  22.             if (isset ($_POST['ok']) && isset($_POST['check'])) {
  23.                 $_SESSION['check'] = $_POST['check'];
  24.             }
  25.         ?>
  26.     </body>
  27. </html>
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy. OK, I Understand
 
Top