Welcome to the Treehouse Community
Looking to learn something new?
Yusuf Bagha24,370 Points
Taking Info from a form to another form on another webpage
I'm having an issue with designing something and i'm looking for help.
What i'm trying to accomplish is taking the data a user has written in a text box and putting it onto another text box on another webpage after the user has clicked submit.
For example, User1 writes "apples" in the text box named "fruit". User1 then presses a button which directs him to another url that has the text boxes "fruit", "veggies", and "meats". When User1 gets to the second webpage with multiple text boxes he finds that the text box fruit is already filled in with the string data he provided in the first webpage
i'm looking for a way a user can input data onto textboxes(forms), and then press a button which is linked to another webpage that has those textboxes and more textboxes
Ethan LowryCourses Plus Student 7,323 Points
You would have a HTML form on your initial page with an 'action' attribute containing the URL of your second page, so that submitting the form will pass its data and direct the user to that page. In the code for this second page (I'm assuming you're probably working with PHP here but you haven't specified) you will check the array of POST data for values with the names of your inputs from the first page e.g.
$fruit = $_POST['fruit'];
Then, if a value is found, you can do whatever you want with it, such as use it to fill in another textbox in this case. You might, for example, do this using an if/else which checks if the $fruit variable is null or not, and writes either an empty or non empty text field to the page accordingly.
Hopefully this helps somewhat - everything here is very common stuff so you should have no issues Googling a good solution once you know what to look for.