Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations bkrike on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Getting Data From Two Forms

Status
Not open for further replies.

bam720

Technical User
Sep 29, 2005
289
US
Preface: I have done my whole site in php and am unfamiliar with javascript. The php guys said it is unlikely i can solve my problem through php so I am trying here. Thanks.

I have two forms on my page. The top form contains three dropdown list boxes that submit the page on change. The reason for this is that the second drop down is dynamically populated after the first has been selected. Same for the third but based on the second. The bottom form contains three text boxes. What happens is if the user skips the three dropdown boxes and starts filling out the text boxes, then returns to the drop down boxes, anything they have already typed in the text boxes is lost and reset with the initial page values. Is there a way that when the top form autosubmits based on the javascript:
Code:
onchange="this.form.submit()"

that the data can be read from the lower textboxes and be stored, either by session varibles, post/get array or anything else? I am asking for a starting point or suggestion and some smaple code, if you like/need I can provide my page's code. Thanks.
 
You could put the top form in an iframe. That way when it submits, it only affects that form. Otherwise, i've seen ways that javascript can be used to populate the other boxes without even submitting the form. I.e. You can pull all the values for all 3 boxes and then put them into arrays, and use javascript to populate the other boxes as options are selected.
 
Why not put all of the content on a single form?
At the top of your PHP page you read in all of the form fields and populate the fields with the data as the page is built. That way no matter if the page was submitted in order to get new select box options you will be able to retrieve and set the other values on the form as well.

A better method is to use AJAX to go get the select box options without having to submit the page when a select is changed, but this requires more work to get it setup than the above method would.


It's hard to think outside the box when I'm trapped in a cubicle.
 
that was also what i was going to suggest, setting the values of the other fields as $_POST['field'], but since he mentioned it being in 2 separate forms, i thought for some reason it may need to be in 2 separate forms.

And I have seen the AJAX method, but i think i would get in trouble for posting a link to it on the forum...
 
This is the final page so its in two forms so that the top form only affets the drop down boxes. After they are selected they create hiddent text field in the lower form with their values and when the lower form is submitted it is all entered into a database. I will look into the iframe idea. Thanks
 
You would not have to have it as two forms though if you put your select box code into the same script page as the DB submission form. You can set a value either in a hidden form field or directly on the URL that indicates which state the code should operate in. Then you have only one form and one processing page. The change to your code is minimal and on your processing page you check one value and use an if statement to determine which functions to run.
It should be a 5 minute change as opposed to learning and dealing with iframes.



It's hard to think outside the box when I'm trapped in a cubicle.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top