I hope I can explain this clearly ...

I have a drop down list in a form, in a PHP page, the form is displayed via 'echo'.

The FORM ACTION tags looks like this:

echo "<CENTER><FORM NAME='choose_lib' METHOD='post' ACTION='viewpix.php?ctPos=360&ctWid=109&hsp=1&loc= XXX '>"; 

When the user selects a name from the drop down list, which is dynamic, how can I get that variable into that ACTION url where it currently says XXX ? All I can think of is that I am going to need an intermediate page, and that doesn't sound very efficient. Pretty new at this stuff, hope someone can help. Thanks for looking....

    It sounds like you do not need that: you can access that variable via $_POST.

      Edited: I like laserlight's answer better.

        you can access that variable via $_POST.<

        That's what I thought, and I tried a few ways ... such as:

        "...&loc= " .$_POST[search_name] . " '>";

        "...&loc= " $search_name '>";

        but couldn't seem to find the right syntax. As you can see, I am still a hacker, but I am working on it! 🙂

          Here is what I tried last. I seem to have exhausted my very limited understanding about this. I have tried breaking out to of the <?PHP tags and removed the echo's and tried this in the query string:

          <FORM NAME='choose_lib' METHOD='post' ACTION='viewpix.php?ctPos=360&ctWid=109&hsp=1&loc=<? echo '$_POST[search_name]' ?>'>

          But all that does is return the code. I know that is because I have the quotes, but without the quotes, it is still blank. Somehow I am not capturing the value, but I don't know why. Any help is very appreciated.

            First, remove the "loc" variable from the URL in the action value like this:

            ACTION='viewpix.php?ctPos=360&ctWid=109&hsp=1'

            Second, Open up viewpix.php and add this command near the top:

            $loc = $_POST['search_name'];

            See, if there is a drop down field for "search_name", then it's value will get posted to the next page (the page in the action tag - which is viewpix.php).

            And since the value of that drop down field is already getting passed (posted) to the next page, there is no reason or need to "put" it into the loc variable in the action URL. Once the search_name arrives at the next page, you can use the command I gave you to copy the value into the $loc variable.

              Yes, I am already using the 'search_name' variable in the next page. What I am attempting to do with it in the query string as well is to import the value into a Flash file. My code that displays the Flash is dynamic as well, keeping the user from having to click the control to activate it - IE requires the user to click an ActiveX control. So, in order to get my value imported into the Flash movie, it has to be in the query string.

              Make sense?

                Make sense?

                No, that's not how it works.

                This pages passes values to the next page. It doesn't matter whether they are in the form field or the query string... once they arrive at the next page, they are simply values that were delivered from the previous page.

                Since you are already passing "search_name" to the next page in the form, there is no need to pass it again twice in the query string. That would be redundant and doesn't gain you anything.

                  The only way the Flash file can import the variable value, is through the query string. It won't import from the $_POST - at least not with all the other dynamic code for bypassing IE requirement for user click to activate. So - although I am successfully using POST DATA in the viewpix.php page, Flash cannot import from there. Flash will only import from the URL in this case.

                    You are mixing up two requests.

                    The first request is a post from page A to page B.
                    The second request is to obtain the Flash movie.

                    Page B will include some HTML that has an embed statement that tucks the Flash movie into that page. And you are correct, when you do that embed, you have to pass the parameters to Flash with a GET.

                    How you move from page A to page B has no bearing on the function of the Flash movie. It's Ok if all the data transferred from page A to page B goes via a POST.

                    Let's put it another way: When your users visit your web site, their browser is going to do TWO things.

                    First, they will be on the page with the form. They will fill in the form (selecting from drop down menus, etc), and they will click continue. That will cause their browser to request page B. That is the first thing. It's a complete, self contained action. All the data goes from the form to page B.

                    When page B receives all the data from the form... it will construct some HTML. That HTML can be anything you want. Maybe some text, tables, whatever. Part of that HTML will be to build an embed tag that calls the Flash. (This has to be a GET). So when you are constructing the HTML for the embed, you will include variables that you got from the previous page. It doesn't matter how they arrived from the previous page. It could be GET, it could be POST, it could come from a database, or the data could arrive at page B in a dozen other ways. The PHP for page B will build the HTML for that page and give it to the user's browser. That is the end of the first thing that the browser does. See? Make a request, get some HTML as a response. Done.

                    Then the user's browser does a second thing. Now that it has this HTML (with the Flash embed tag in GET form), the user's browser will make a brand new request out to the Internet asking for the Flash movie. Of course, you want to pass in parameters into the Flash movie so you have to call the movie with a GET. The server returns the Flash movie to the user's browser and the movie receives the variables that were in the GET statement. But that is a completely separate event from the posting of data from page A to page B.

                    Page A will look like this:

                    <form action="pageB.php" method=post>
                    // input tags and select tags go here
                    </form>
                    

                    And Page B will look like roughly this:

                    $loc = $_POST['loc'];
                    print "<embed src=\"http://www.foo.com/something.swf?loc=$loc\">";
                    

                    See?

                      That is a great explainantion and I thank you for taking the time for all of that. Although it doesn't correct my issue, you clarified a couple other things for me.

                      The dilema is this: when using an <EMBED> tag, IE requires the user to click on the control, a real pain in the ***. The work around I am using is the "swfobject.js" script that places the Flash movie on the page without using any embed tags. The tradeoff is that the Flash movie can then only be sent variables through the query string. That's it: no options, no embed tags, no other way to pass values. So I have to to get that variable value up in the URL string in order for it to get into my Flash movie.

                      I think I am stuck with using an intermediate page on this one. Unless there is something obvious and simple that I am missing - which is often the case! 🙂

                        Dude, I've done this a hundred times... including using JS to insert the flash movie instead of using embed tags.

                        Wherever the URL is (whether it's in an embed tag or if it's in the Javascript), it can be built dynamically with PHP.

                        Remember, you are building something on the server - and you can do that dynamically - and once it's built, then it's sent as simple HTML or Javascript to the user's computer where it will run.

                        Probably the easiest way to handle this is to include the Javascript into the HTML file that the PHP is building like this:

                        include ("swfobject.js");

                        And then put PHP tags inside the JS file. This way, they will get parsed. The variables that PHP knows can be written into the Javascript, and when the user gets the HTML file (with the Javascript already in it), the Javascript will be altered for their particular situation. Think of it as dynamic javascript.

                        So if you looked in swfobject.js, it might have a line that looks roughly like this:

                        url = 'http://www.foo.com/something.swf?loc=<?php print "$loc"; ?>';
                        

                        (Another way to do it is to turn on PHP parsing for JS files - and we can discuss that if you want - but I suggest going one step at a time - just include the JS in the HTML for now.)

                        You are so close. I promise you, learning this is worth the effort. Using PHP to alter Javascript to call dynamic flash movies is uber cool, not that difficult, and puts you far ahead of the script kiddies who got a copy of Flash for Christmas and call themselves web designers.

                          OK, you convincedme that you DO understand what I am talking about. I am going to work on this some more. I spent the day getting from Plainfield, to O'Hare, to Las Vagas, so it will be a few days before I am back in my office to pick this up again.

                          I know what you mean about Flash Kiddies thinking they have this down. I have been useing flash since V.3 and WOW has it come a long way. I have written some pretty cool AS apps along the way. learning some basic PHP and MySQL is my latest undertaking. Thanks for your help. Hope I can figure out what you mean once I get back! 🙂

                            Ok, first of all, I'm really jealous because I love going to Vegas.

                            Second of all, read this when you get back. I think it will make perfect sense:

                            Let's say that you make a Flash movie that takes a parameter (a string) and it displays the text spinning around in a circle like the hands on a clock. A fairly basic Flash Actionscript - except that it's cool because it takes a parameter and works with that.

                            And the parameter comes from a form. That is, you see a form, you type in a word, you click continue and then you see the word spinning round and round like a propeller or something. No intermediate page. Here's how you do it:

                            1. Make a form. Call it page_a.html
                            <form action="page_b.html" method=post> <!-- notice the POST method -->
                            Enter your word: <input type=text name=word>
                            <input type=submit value=Go>
                            </form>
                            
                            1. Make a page to display the Flash. Call it page_b.php
                            <?php
                            //  Notice that "word" got POSTED from the form on the previous page
                            $word = $_POST['word'];
                            ?>
                            <html>
                            <head>
                            <script language="Javascript">
                            <script type="text/javascript" src="swfobject.js"></script>
                            </script>
                            </head>
                            <body>
                            This is some text at the top of the page
                            <div id="flashcontent">
                               This text is replaced by the Flash content.
                            </div>
                            <script type="text/javascript">
                            
                            //  Javascript comment:
                            //  Just pointing out that the next line is using Javascript to "embed" the Flash
                            //  And that Javascript is calling the SWF with a query string url in GET mode.
                            //  That Query string url is created using variables that were received via
                            //  A POST method from the previous form. 
                            
                               var so = new SWFObject("text_spinner.swf?string=<?php print "$word"; ?>", "mymovie", "200", "100", "7", "#336699");  
                            so.write("flashcontent"); </script> </body> </html>

                            Hey! You got PHP in my Javascript!

                            Notice that I am creating the Javascript call on the fly. I'm doing that up on the server. Once the HTML/Javascript page is created, it gets sent down to the user's machine as simple text - no PHP. The user's machine displays the page - it makes the call out to Flash (via the get method). It doesn't matter how the "word" variable got into the URL. It could have been hard coded into the Javascript by being typed on a keyboard - it could have come from a database - it could be the result of contents received from a form (which it was) - it could have been a result of a random number generator. The client machine has no reason to care where that Javascript came from. If you hit "View Source" on the page_b.php (where the Flash is displayed), you will notice that the URL inside the Javascript looks like normal text... because it is normal text.

                              7 days later

                              YEAH BA-BY! I am not so sure I understand it, but it works!! It does wipe the other variables that are set from the URL from other pages, but that is an easy fix.

                              Thanks for being patient with me on this. I know I am hard headed at time. :queasy:

                                Write a Reply...