Unable to POST a Variable Received by postMessage

I have encountered an issue wherein a value received on a parent page from an IFRAME is not being POSTED. A FORM variable is set with the valude of the data received from postMessage. I can verify that the variable is being set using alert();

I have an working example of this scenario which can be found here:

http://www.maglin.com/dev/php/iframe/15/

When you click on Submit Query (inside the IFRAME), it will seem as if nothing happened, but what this does is submit the string "This is another one" to the parent. In the parent (which has the SUBMIT button) the value of a variable called js_var is set in a FORM with the data received by postMessage. That is, js_var is set to "This is another one". So, when you click the SUBMIT button, the variable js_var is POSTed to a file called post.html.

At the top of post.html I have the followig PHP code which shows what has been POSTed.

<?php

print_r($_POST);

?>

You'll see that the string "This is another one" has been assigned to js_var.

Output is:

Array ( [js_var] => This is another one )


All good.

I am trying implement something similar for our website, but the value submitted by postMessage is not being POSTed.

Starting here:

http://www.maglin.com/products/bench/mlb100series-bw.html

when this page is displayed, you will see an alert(); which shows an empty array.

Now go to the CONFIGURE & QUOTE tab to see product options which are displayed in an IFRAME

For testing, choose:

Ipe

from the SELECT a Material section

Choose

Center Arm

from the Options section

Click the Proceed to Quick Quote button

You will now see that the alert() displays an array containing the options you chose.

This alert is showig you the value of js_var, which is a hidden INPUT in the FORM surrounding the ADD TO QUOTE button on the parent (to the right of the IFRAME).

After clicking OK on the alert() you can click the ADD TO QUOTE button, just as in the example above, is supposed to POST js_var to a file called post.html. However, in this case, the POSTed array is empty!

Output is:

Array ( )

I have tried setting the value used for for postMessage to just a string, in case there was something wonky with the array for the product option selection, but this did not work either. I still get an empty POSTed array.

Hope you can help!
MaglinFurnitureAsked:
Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

GaryCommented:
There is no FORM on your parent page which may explain this error.

TypeError: document.forms.form is undefined
document.getElementById("js_var").value=event.data;


p.s.
there is no alert either.
0
MaglinFurnitureAuthor Commented:
Sorry, my bad. Try now
0
Dave BaldwinFixer of ProblemsCommented:
After a PHP page is opened in the browser, you can't POST anything to it.  The PHP has already executed and sent the results to your browser.  POSTing to another copy of it on the server will not make anything show up in your browser.
0
The Ultimate Tool Kit for Technolgy Solution Provi

Broken down into practical pointers and step-by-step instructions, the IT Service Excellence Tool Kit delivers expert advice for technology solution providers. Get your free copy for valuable how-to assets including sample agreements, checklists, flowcharts, and more!

GaryCommented:
Let's play a game of Spot the difference

methoc ='POST'
method ='POST'

Had me for a few minutes understanding why it was GETting the data
0

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
Dave BaldwinFixer of ProblemsCommented:
Well, that doesn't help either...
0
GaryCommented:
What doesn't
Is my answer too cryptic that there is a typo in the code?
0
Dave BaldwinFixer of ProblemsCommented:
No, that's what I meant.  methoc ='POST'  Explains pretty exactly why POST isn't working since GET is the default method.
0
GaryCommented:
Ohhh ok ;o)
0
MaglinFurnitureAuthor Commented:
@GaryC123

>>Let's play a game of Spot the difference
>>
>>methoc ='POST'
>>method ='POST'
>>
>>Had me for a few minutes understanding why it was GETting the data


ARGHH@$#!

I knew it was going to be something like that!

Thanks!
0
GaryCommented:
@ MaglinFurniture
We'll have your site flying along before you know it :o)
0
MaglinFurnitureAuthor Commented:
@GaryC123

Yes, I think a lot of people will be very happy with this. Thanks again for all your help!

@DaveBaldwin

>>After a PHP page is opened in the browser, you can't POST anything to it.  The PHP has >>already executed and sent the results to your browser.

True

>> POSTing to another copy of it on the server will not make anything show up in your >>browser.

I'm not quite sure what you meant by this. I assume you didn't mean that you can't POST FORM values to a PHP page. $_POST is a PHP array specifically designed to capture POSTed data. $_GET captures data sent using the GET method.

I had thought of trying to see if the data has been passed using GET. I even thought of starting to look for syntax errors or typos, but was too bleary eyed and weary at end of day yesterday, so I thought a new set of eyes would help. And it did!
0
Dave BaldwinFixer of ProblemsCommented:
I misunderstood what you were trying to do.  A lot of people seem to try to get PHP to act like javascript and of course it doesn't.  

Of course you can post form data to a PHP page... but it won't change the page that is already in your browser without some AJAX to get the results.  The $_POST array that was used to display the current page in your browser is long gone.

I have a pretty good understanding of PHP forms, methods, and pages.  People hire me to do those, especially form to email pages.
0
MaglinFurnitureAuthor Commented:
@DaveBalwin

Ah, excellent!

I haven't gotten into Ajax. I hardly know anything about JavaScript. In my original foray into JavaScript (about 10 years ago or so ) I started to write a shopping cart application, using JavaScript for verifying registration forms etc. Then one day someone said that all people have to do is turn off JavaScript and all the validation will no longer work! So, that was the end of my foray into JavaScript.

I'm not quite sure what you mean by "The $_POST array .... is long gone" -- the last time I hd to upgrade PHP for our site I had to go around and get rid all the references to $HTTP_POST_VARS because it was deprecated!
0
Dave BaldwinFixer of ProblemsCommented:
"The $_POST array .... is long gone" means that when that page is finished executing, all the data including the $_POST array disappears.  The $_POST array is created each time by info passed from the web server.
0
MaglinFurnitureAuthor Commented:
@DaveBaldwin

Ah, gotcha!
0
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
Scripting Languages

From novice to tech pro — start learning today.