SitePoint Sponsor

User Tag List

Results 1 to 4 of 4
  1. #1
    Don't eat yellow snow spaceman's Avatar
    Join Date
    Mar 2001
    Location
    Melbourne, Australia
    Posts
    1,039
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    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.

    I'm using PHP & MySQL by the way, with Javascript where appropriate. My hunch would be that the solution involves some javascript in the FORM element, but my Javascript talents aren't that hot.

    Any suggestions anyone?

  2. #2
    SitePoint Zealot HotDog's Avatar
    Join Date
    May 2000
    Location
    Salt Lake City, UT
    Posts
    108
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    How are you using the form data in both frames?

    When the frame with the form is submitted, that form information is only available in that frame to PHP. What you could do then, is write a javascript in PHP that passes the values to the other frame.

    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.

    Also, try posting in the PHP/MySQL forum. There are bigger fish than me there that can answer your php questions better than I can. If it's a javaScript solution, I can help, but you'd have better luck with this question in the other forum I think.
    Joe Eliason
    Just a dog learnin' PHP from cat.

  3. #3
    Don't eat yellow snow spaceman's Avatar
    Join Date
    Mar 2001
    Location
    Melbourne, Australia
    Posts
    1,039
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    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" ... >

    Of course the above will not work, but it helps to explain what I'm trying to achieve. I'm convinced that javascript will be the solution, because I know it can do 'fancy' things on the client-side.

  4. #4
    SitePoint Zealot HotDog's Avatar
    Join Date
    May 2000
    Location
    Salt Lake City, UT
    Posts
    108
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Try this:

    Setup your frame page:

    Code:
    <html>
    <frameset cols="18%,82%">
    		<frame name="frameA" src="frameA.php">
    		<frame name="frameB" src="frameB.php">
    </frameset>
    </html>
    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.

    Code:
    <html>
    <body>
    
    <form method="post" action="<?=$PHP_SELF?>" name="formA">
    <input type="hidden" name="value1" >
    </form>
    <?php	
    echo $value1;
    ?>
    </body>
    </html>
    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.

    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:

    Code:
    <html>
    <head>
    <?php
    	if ($edit) : ?>
    <script language="javaScript">
    	parent.frameA.document.formA.value1.value="<?=$value1?>";
    	parent.frameA.document.formA.submit();
    </script>
    <?php
    	endif;
    ?>
    </head>
    <body>
    <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">
    <br><br><br>
    <?php 
    	print $value1;
    ?>
    
    </body>
    
    </html>
    If you copy this exactly into three pages, you will be able to see it working.

    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.

    Ruff!!!
    Joe Eliason
    Just a dog learnin' PHP from cat.


Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •