Hi, I'm new to this community and hope im in the right place :-) I have been searching everywhere for the proper method to pass input from one html form to another. I have found a bunch of javascript that is supposed to break down a query string and populate the second form based on that, but no matter what i try i cant get it working. Basically, im trying to have a small form on the main page where a user would enter some basic info (name, etc.) and also choose from a drop down menu for one selection. Then on clicking submit, that would launch the full form, populated with the data they filled out, and including new input fields. Ive seen this a hundred times, so im thinking it shouldnt be so difficult to do, but for some reason im stumped. any help is greatly appreciated.

Do you mean that the form is loaded without the page being refreshed/changed or with the page refresh?

Anyway, if the page is refreshed after the user pressed the button, you can just simply retrieve the form values using PHP and then echo that as values inside the full form:

// Retrieving the form values of the small form:
$firstname = $_POST['firstname'];
$lastname = $_POST['lastname'];

// Echoing them inside the full form:

echo "First name: <input type='text' name='firstname' value='".$firstname."' />";
echo "Last name: <input type='text' name='lastname' value='".$lastname."' />";

// The rest of the form:

echo "Address: <input type='text' name='address' value='' />";
echo "Zip: <input type='text' name='zip_code' value='' />";

Or if you want the full form to show up dynamically (without page refresh) you will need to write a JavaScript function that either shows the rest of the form (which is hidden untill the button is pressed) or that retrieves the form values of the small form and then inserts them into the full form and then focusses the first input field within that form.

You can retrieve values using JavaScript with the following function (the id of the text input also needs to be set on 'lastname', just like its name):

var LastName = document.getElementById('lastname').value;


Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts learning and sharing knowledge.