swraman Posted May 12, 2013 Share Posted May 12, 2013 (edited) This has me stumped. It was workign fine but 30 minutes ago! Body of my form: <form name="form1" id="form1" action="process.php" method="post"> <textarea cols="50" rows="4" id="src" name="src"></textarea> <input type="submit" value="Submit"> </form> process.php: <?php print_r($_POST); ?> process.php displays: Array() regardless of what I have in the text box. Edited May 12, 2013 by swraman Quote Link to comment https://forums.phpfreaks.com/topic/277917-_post-reads-an-empty-array/ Share on other sites More sharing options...
trq Posted May 12, 2013 Share Posted May 12, 2013 You are of course submitting the form? Quote Link to comment https://forums.phpfreaks.com/topic/277917-_post-reads-an-empty-array/#findComment-1429661 Share on other sites More sharing options...
swraman Posted May 12, 2013 Author Share Posted May 12, 2013 I have an iframe in my form page. When I take it out, it works fine! Is there something wrong with using iframes and POSTing data? Quote Link to comment https://forums.phpfreaks.com/topic/277917-_post-reads-an-empty-array/#findComment-1429662 Share on other sites More sharing options...
swraman Posted May 12, 2013 Author Share Posted May 12, 2013 (edited) And yes, I am clicking submit. I assume that somehow the server is reading the submitting webpage to be the webpage in the iframe, and not the actual page on my server. Is this the case? Edited May 12, 2013 by swraman Quote Link to comment https://forums.phpfreaks.com/topic/277917-_post-reads-an-empty-array/#findComment-1429663 Share on other sites More sharing options...
jazzman1 Posted May 12, 2013 Share Posted May 12, 2013 I've never use forms in iframes. Can you show us the sample of the code? Quote Link to comment https://forums.phpfreaks.com/topic/277917-_post-reads-an-empty-array/#findComment-1429666 Share on other sites More sharing options...
swraman Posted May 12, 2013 Author Share Posted May 12, 2013 (edited) I typically don't use iframes either, but for this project I have to use access a part of another website which requires users to login. Here is the full code: <html><head> <script type="text/javascript"> function getsome(){ w = document.getElementById('inline').contentWindow.document.body.innerHTML; document.getElementById("src").value=w; } </script></head> <body> <br> <a href="#" onclick="getsome()">Push me</a><br> <form name="form1" id="form1" action="process.php" method="post"> <textarea cols="50" rows="4" id="src" name="src"></textarea> <input type="submit" value="Submit"> </form> <iframe name="inline" id="inline" frameborder="0" scrolling="auto" width="1000" height="300" marginwidth="5" marginheight="5" src="http://website.com/"></iframe> </body> </html> This script is meant to copy the source of a website into the form (done with JS, which works), then submit that form to process.php. Edited May 12, 2013 by swraman Quote Link to comment https://forums.phpfreaks.com/topic/277917-_post-reads-an-empty-array/#findComment-1429668 Share on other sites More sharing options...
swraman Posted May 12, 2013 Author Share Posted May 12, 2013 Update: I removed the iframe again and it seems like that was not the issue. Without the iframe, it works about half of the time...which makes no sense to me. Any suggestions? Quote Link to comment https://forums.phpfreaks.com/topic/277917-_post-reads-an-empty-array/#findComment-1429670 Share on other sites More sharing options...
mac_gyver Posted May 12, 2013 Share Posted May 12, 2013 your process.php page is probably redirecting back to itself and clearing the $_POST data and/or you don't have an exit; statement after a redirect to prevent the rest of your code from running. you need to post the code that reproduces the problem. not all your code, but the code you do post must have been tested by you and it reproduces the problem. Quote Link to comment https://forums.phpfreaks.com/topic/277917-_post-reads-an-empty-array/#findComment-1429671 Share on other sites More sharing options...
swraman Posted May 12, 2013 Author Share Posted May 12, 2013 Looks like i found out what was going on. The problem happens when I open the link in a new tab. I have neverf seen this happen before - is this a common problem using post vars? Quote Link to comment https://forums.phpfreaks.com/topic/277917-_post-reads-an-empty-array/#findComment-1429672 Share on other sites More sharing options...
mac_gyver Posted May 12, 2013 Share Posted May 12, 2013 what link? what new tab? $_POST data will be available only on the page that is the target of the form. anything you do to goto a new page or refresh that page will clear the $_POST data. and did you see the post i made above about your process.php code? Quote Link to comment https://forums.phpfreaks.com/topic/277917-_post-reads-an-empty-array/#findComment-1429673 Share on other sites More sharing options...
swraman Posted May 13, 2013 Author Share Posted May 13, 2013 Thanks for the reply. No, my process.php was not redirecting anywhere. It was just a single line, <?php print_r($_POST); ?>. I meant that when I clicked on the submit button to submit the form, I was opening the form in a new tab. This made the $_POST array in the receiving process.php file be empty. If I submit the form in the same tab, it works fine. Quote Link to comment https://forums.phpfreaks.com/topic/277917-_post-reads-an-empty-array/#findComment-1429795 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.