Welcome to the Treehouse Community

The Treehouse Community is a meeting place for developers, designers, and programmers of all backgrounds and skill levels to get support. Collaborate here on code errors or bugs that you need feedback on, or asking for an extra set of eyes on your latest project. Join thousands of Treehouse students and alumni in the community today. (Note: Only Treehouse students can comment or ask questions, but non-students are welcome to browse our conversations.)

Looking to learn something new?

Treehouse offers a seven day free trial for new students. Get access to thousands of hours of content and a supportive community. Start your free trial today.

General Discussion

Yusuf Bagha
Yusuf Bagha
24,370 Points

Taking Info from a form to another form on another webpage

Hey,

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
PLUS
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.