1

I have a form that have a select input, and there's another pop up that sets a session. i want to save the selected values while the page reloading for the session setting is there's any solution for that ?

example of my code

<script src="https://maxcdn.bootstrapcdn.com/bootstrap/4.0.0/js/bootstrap.min.js"></script>
<link href="https://maxcdn.bootstrapcdn.com/bootstrap/4.0.0/css/bootstrap.min.css" rel="stylesheet"/>

<form method="post" action="">
    <select name="first">
    <option value="example1">first opt</option>
    <option value="example2">second opt</option>
    </select>
    <input type="submit" value="Done">
    </form>

    <p>you have added > <?php echo $_SESSION['sessionset']; ?></p>
    <button data-toggle="modal" data-target="#myModal">Adding something by setting a session</button>
    
    
    <div id="myModal" class="modal fade" role="dialog">
  <div class="modal-dialog">
 <button type="button" class="close" data-dismiss="modal">×</button>
</div>
<div class="modal-body">

   <form method="post" action="">
    <select name="sessionset">
    <option value="cupcake">cupcake</option>
    <option value="cookie">cookie</option>
    </select>
    <input type="submit" value="Done">
    </form>
  
  </div>
  </div>

php

 if(isset($_POST['sessionset'])) {
        $_SESSION['sessionset'] = $_POST['sessionset'];
    }

this is a little example of my page, now i need to set the session and i don't want the user to reset his select because of the reload

  • Possible duplicate of [How do I set/unset a cookie with jQuery?](https://stackoverflow.com/questions/1458724/how-do-i-set-unset-a-cookie-with-jquery) – Jaquarh Jul 27 '19 at 16:49
  • you can save it in the session variable, but you have to submit it. You also could save it to localstorage using javascript. or you could save it to the cookie, not recommend. – Sascha Grindau Jul 27 '19 at 17:07

0 Answers0