Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>You're losing the data sent to the server when you do the redirect.</p> <p>Basically, you've got 3 options:</p> <ul> <li>Store the data on the client using a cookie or similar (A lot of overhead for something simple)</li> <li>Store the data server-side in a session or similar (even more overhead)</li> <li>Pass the data through the URL you're redirecting to...</li> </ul> <p>So something like:</p> <pre><code>if (array_key_exists($_POST['dropdown-name'], $pages)) { header("Location: " . $pages[$_POST['dropdown-name']] . "?personsName=" urlencode($_POST['name'])); } else { //Blah } </code></pre> <p>Which seems to be the best answer for your simple example. If there's a LOT of data or it's more complex, consider using one of the other 2 option above</p> <p>NB: On the form you've called the variable <code>name</code>, on the pae receiving it, you've called it <code>personsName</code> - note the mapping from one to the other in the URL.</p> <p>Javascript solution (tested):</p> <pre><code>&lt;html&gt; &lt;head&gt; &lt;title&gt;SO Demo&lt;/title&gt; &lt;/head&gt; &lt;body&gt; &lt;script type="text/javascript"&gt; function UpdateFormAction(){ var form = document.getElementById('MyForm'); var list = document.getElementById('PageList'); var desiredAction = list.options[list.selectedIndex].value form.action = desiredAction; document.getElementById('Target').innerHTML = 'Form action set to: ' + desiredAction; } &lt;/script&gt; &lt;form id="MyForm" action="letter.php" method="POST"&gt; Name: &lt;input type="text" name="name" /&gt;&lt;br /&gt; Page: &lt;select id="PageList" name="letter" onchange="UpdateFormAction();"&gt; &lt;option value="letter.php"&gt;Page 1&lt;/option&gt; &lt;option value="letter2.php"&gt;Page 2&lt;/option&gt; &lt;option value="letter3.php"&gt;Page 3&lt;/option&gt; &lt;/select&gt; &lt;input type="submit" value="Print" /&gt;&lt;br/&gt; &lt;span id="Target"&gt;Form action unmodified&lt;/span&gt; &lt;/form&gt; &lt;/body&gt; &lt;/html&gt; </code></pre>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. VO
      singulars
      1. This table or related slice is empty.
    2. VO
      singulars
      1. This table or related slice is empty.
    3. VO
      singulars
      1. This table or related slice is empty.
 

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