Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 3805780
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 19, 20262026-05-19T14:43:55+00:00 2026-05-19T14:43:55+00:00

I have asked two previous questions for taking info put into a form and

  • 0

I have asked two previous questions for taking info put into a form and using it to populate a page, and one to redirect you to a page when you submit the form based off of what you choose in the forms drop down. Now I need these two things to both work for the same form.

The code for taking the info from the form and using it to populae the next page is:

<?php
$firstname = $_GET['personsName'];
echo "My Name is" .$firstname;
?>

And the form would look like this:

<form action="letter.php" method="get">
<input type="text" name="personsName"></input>
<input type="submit" value="submit">
</form>

The code for selecting a page is:

$pages = array('Page 1' => 'page1.php', 'Page 2' => 'page2.php', 'Page 3' => '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
}

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:

<form action="<?=$pages?>" method="POST">
<input type="text" name="name" /><br />
<select name="letter">

<option value="Page 1">
Page 1
</option>

<option value="Page 2">
Page 2
</option>

<option value="Page 3">
Page 3
</option>

</select>
<input type="submit" value"Print" />
</form>

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!

Current code is this:

<script type="text/javascript">
$(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;
});
</script>

Form is:

<form id="MyForm" action="letter.php" method="POST">
<input type="text" name="name" /><br />
<select id="PageList" name="letter" onchange="UpdateFormAction();">

<option value="letter.php">Page 1</option>
<option value="letter2.php">Page 2</option>
<option value="letter3.php">Page 3</option>
</select>
<input type="submit" value"Print" />
</form>
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-19T14:43:56+00:00Added an answer on May 19, 2026 at 2:43 pm

    You’re losing the data sent to the server when you do the redirect.

    Basically, you’ve got 3 options:

    • Store the data on the client using a cookie or similar (A lot of overhead for something simple)
    • Store the data server-side in a session or similar (even more overhead)
    • Pass the data through the URL you’re redirecting to…

    So something like:

    if (array_key_exists($_POST['dropdown-name'], $pages)) {
        header("Location: " . $pages[$_POST['dropdown-name']] . "?personsName=" urlencode($_POST['name']));
    } else {
        //Blah
    }
    

    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

    NB: On the form you’ve called the variable name, on the pae receiving it, you’ve called it personsName – note the mapping from one to the other in the URL.

    Javascript solution (tested):

    <html>
        <head>
            <title>SO Demo</title>
        </head>
        <body>
    
        <script type="text/javascript">
            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;
            }
        </script>
    
        <form id="MyForm" action="letter.php" method="POST">
            Name: <input type="text" name="name" /><br />
            Page: <select id="PageList" name="letter" onchange="UpdateFormAction();">
                <option value="letter.php">Page 1</option>
                <option value="letter2.php">Page 2</option>
                <option value="letter3.php">Page 3</option>
            </select>
            <input type="submit" value="Print" /><br/>
            <span id="Target">Form action unmodified</span>
        </form>
        </body>
    </html>
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

This is a continuation question from a previous question I have asked I now
I have asked a similar question before, but I didn't have a firm grasp
Previously I have asked to strip text from a field and convert it to
I have been asked to lend a hand on a hobby project that a
I have been asked to standardize the screen saver and desktop background used by
I have been asked to develop some usercontrols in ASP.NET that will at a
I have been asked to audit any/all changes in a MySQL table. Does anyone
I have been asked to provide information on available techniques for assessing our current,
I have been asked to setup a course leaflet system for a college. For
I have been asked to find training resources to bring engineers up to speed

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.