Is it possible to submit a form, and for the form data to be passed to more than 1 location at the same time?
I'm working on a shopping cart application using frames. When the user has input some data into a form and clicks SUBMIT, I need all the form data to be available to the code in two different frames at the same time.
I can write the form data to the MySQL database and read it back, but seeing as both of the frames need to act on the form data simultaneously, it's unlikely that script 'A' will finish (or even start) writing the data before script 'B' wants to read it.
Any suggestions anyone?
How are you using the form data in both frames?
I really don't know what you need the values to be passed to in the other frame so I don't know how to really answer you question.
Hi HotDog, and thanks for your interest.
I'm working with multiple frames (I'm not a big fan of frames myself, but the client likes them...), but for the sake of this example I'm only dealing with 2 frames. Frame 'A' is a form. Frame 'B' is the list of items in the customers shopping cart. When the user submits the form in Frame 'A', I need all the user supplied data contained in that form to be passed back to Frame 'A' AND to Frame 'B', since the scripts in both frames need to act upon that data.
I don't feel that it's necessary to understand the application - just that all of the form data needs to be passed to two different scripts/pages/locations simultaneously.
eg. <FORM action="page1.htm" action="page2.htm" ... >
Setup your frame page:
Next, setup your page where you want your information copied to. I called it frameA.php. Setup a form exactly the same as the main form on page 2, except put all the inputs as hidden. Where you want the information visibly placed, put in a php variable the same name as the input field's name. Have the page submit to itself. I used the PHP method.
<frame name="frameA" src="frameA.php">
<frame name="frameB" src="frameB.php">
Lastly, setup your main form page. I called it frameB .php. This is where all the work is going to be done. First of all, setup a php if statement looking for if a variable is present or not, telling server if the form has been submitted. This variable will be setup in the form as a hidden input field. Within this if statement, tell the page to pass the values of the form on this page to the form on the other page. Use the php form var values as the values to pass. (Did you follow that??) In this example I only used one field, in yours you will need set this up for every form field you want to pass.
<form method="post" action="<?=$PHP_SELF?>" name="formA">
<input type="hidden" name="value1" >
Next, tell the other page to submit it's form to itself. This will give the php variables values on the other page.
In your main form, setup a hidden field so when the form is submitted, the php code knows it needs to kick-in at the beginning of the document and pass the values to the other page.
Again, submit the page to itself:
If you copy this exactly into three pages, you will be able to see it working.
if ($edit) : ?>
<form method="get" action="<?=$PHP_SELF?>" name="formA">
<input type="hidden" name="edit" value="1">
<input name="value1" type="text">
<input type="submit" name="SUBMIT">
Try it out and let me know how it works. You will, of course, need to modify it to fit your needs. But if you take this example, it should solve your problem.