Welcome to the Treehouse Community

Want to collaborate on code errors? Have bugs you need feedback on? Looking for an extra set of eyes on your latest project? Get support with fellow developers, designers, and programmers of all backgrounds and skill levels here with the Treehouse Community! While you're at it, check out some resources Treehouse students have shared here.

Looking to learn something new?

Treehouse offers a seven day free trial for new students. Get access to thousands of hours of content and join thousands of Treehouse students and alumni in the community today.

Start your free trial

General Discussion

Yusuf Bagha
Yusuf Bagha
28,853 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

1 Answer

Ethan Lowry
Ethan Lowry
Courses 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.