Note that there are some explanatory texts on larger screens.

plurals
  1. POSave multiple session variables with a form
    text
    copied!<p>I am working on a form with fields for dimensions where a customer can fill these fields in and submit them and they will be saved in session variables. So far I succeeded 1 form, but after saving 1 time the data of the fields it needs to be possible for the costumer that he can fill in a form again (for dimensions) and still another and another etc etc.</p> <p>(I started the session in top of my header)</p> <p>The form:</p> <pre><code>&lt;form method="POST"&gt; &lt;label&gt;A:&lt;/label&gt; &lt;input name="wz_saving_a" type="text" /&gt; &lt;label&gt;B:&lt;/label&gt; &lt;input name="wz_saving_b" type="text" /&gt; &lt;input name="wz_submit_saving_1" type="submit" class="add_button" value="Add" /&gt; &lt;/form&gt; </code></pre> <p>PHP for saving data in $_SESSION:</p> <pre><code>if(isset($_POST['wz_submit_saving_1'])) : // Save submit $_SESSION['wz_submit_saving_1'] = $_POST['wz_submit_saving_1']; // Save wz_saving_a in session $_SESSION['wz_saving_a'] = $_POST['wz_saving_a']; // Save wz_saving_b in session $_SESSION['wz_saving_b'] = $_POST['wz_saving_b']; endif; </code></pre> <p>After submit I show the submitted data to the costumer like:</p> <pre><code>&lt;?php if(isset($_SESSION['wz_submit_saving_1'])) : ?&gt; &lt;div id="wz_config_1" class="wz_config"&gt; &lt;ul&gt; &lt;li&gt;Your dimensions:&lt;/li&gt; &lt;li&gt;A: &lt;?php if(isset($_SESSION['wz_saving_a'])) : echo $_SESSION['wz_saving_a']; endif; ?&gt; mm&lt;/li&gt; &lt;li&gt;B: &lt;?php if(isset($_SESSION['wz_saving_b'])) : echo $_SESSION['wz_saving_b']; endif; ?&gt; mm&lt;/li&gt; &lt;/ul&gt; &lt;?php endif; ?&gt; </code></pre> <p>So this works for 1 submit and if I submit the form the session variables of the first will be refreshed by the new data, but now I need something to do so the costumer can add multiple dimensions sets and save in the Session.</p> <p>My idea was to change every name of a field by _1 _2 _3 after each form submit. But I don't know how to fix this so I hope someone can give me some advice.</p> <p>I can give the url of my example if you want?</p> <p>Thanks!</p>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload