开发者

Get Input data from iframe with PHP

I have a page with a form, and in the middle of the form I placed an iframe with HTML inputs boxes. How can I grab their content using PHP $_POST? I tried to do it as I normally do with forms:

$iframe = $_POST["iframe"];

But it didn't grabbed it.

How can I grab the inputs value from t开发者_开发百科he iframe?


The content in the iframe is a different webpage. You need to post the form from the iframe for php to access it.

If you need all the data from the iframe and main page at the same time, you would probably need to use javascript to either:

1) Submit both forms and handle the split serverside 2) Read the values from the iframe and submit as part of the parent page


This won't work, unless the iframe is POSTing to your PHP script. The browser won't send data contained in an <iframe> to your script if the form that's being submitted is in the parent page.

One workaround is to use JavaScript to extract data from the iframe when the form is submitted. Then dynamically attach that data to your POST request.

The iframe's window object can be accessed like so:

var iframe = document.getElementById(iFrameName).contentWindow;

Note that this will only work if the source of the iframe is on the same domain as the parent page (for security reasons).

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜