Note that there are some explanatory texts on larger screens.

plurals
  1. POI need to have a form be filled out, go to a page chosen in a drop down then use the other info from the form to populate the chosen page
    text
    copied!<p>I have asked two previous questions for <a href="https://stackoverflow.com/questions/4605471/make-a-form-in-php-that-saves-information-a-user-gives-and-plugs-it-into-a-anoth">taking info put into a form and using it to populate a page</a>, and one to <a href="https://stackoverflow.com/questions/4771899/php-form-redirect-based-off-of-drop-down-selection">redirect you to a page when you submit the form</a> based off of what you choose in the forms drop down. Now I need these two things to both work for the same form.</p> <p>The code for taking the info from the form and using it to populae the next page is:</p> <pre><code>&lt;?php $firstname = $_GET['personsName']; echo "My Name is" .$firstname; ?&gt; </code></pre> <p>And the form would look like this:</p> <pre><code>&lt;form action="letter.php" method="get"&gt; &lt;input type="text" name="personsName"&gt;&lt;/input&gt; &lt;input type="submit" value="submit"&gt; &lt;/form&gt; </code></pre> <p>The code for selecting a page is:</p> <pre><code>$pages = array('Page 1' =&gt; 'page1.php', 'Page 2' =&gt; 'page2.php', 'Page 3' =&gt; 'page3.php'); if (array_key_exists($_POST['dropdown-name'], $pages)) { header("Location: " . $pages[$_POST['dropdown-name']]); } else { echo "Error processing form"; // submitted form value wasn't in your array, perhaps a hack attempt } </code></pre> <p>I need for both of these to work for the same form, I just haven't been able to figure it out. What I tried was:</p> <pre><code>&lt;form action="&lt;?=$pages?&gt;" method="POST"&gt; &lt;input type="text" name="name" /&gt;&lt;br /&gt; &lt;select name="letter"&gt; &lt;option value="Page 1"&gt; Page 1 &lt;/option&gt; &lt;option value="Page 2"&gt; Page 2 &lt;/option&gt; &lt;option value="Page 3"&gt; Page 3 &lt;/option&gt; &lt;/select&gt; &lt;input type="submit" value"Print" /&gt; &lt;/form&gt; </code></pre> <p>This is obviously wrong. I need this form to take the info put into it, redirect to the page chosen, then populate the page with the other info inputted into the form. The problem is I have no idea how to get the answers I already have together. Thank you to all that help!</p> <p>Current code is this:</p> <pre><code>&lt;script type="text/javascript"&gt; $(function UpdateFormAction(){ alert('Launched event handler'); var form = document.getElementById('MyForm'); var list = document.getElementById('PageList'); alert('List item numer ' + list.selectedIndex); var desiredAction = list.options[list.selectedIndex].value alert('Desired action set to ' + desiredAction); form.action = desiredAction; }); &lt;/script&gt; </code></pre> <p>Form is:</p> <pre><code>&lt;form id="MyForm" action="letter.php" method="POST"&gt; &lt;input type="text" name="name" /&gt;&lt;br /&gt; &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;/form&gt; </code></pre>
 

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