ohdang888 Posted June 16, 2008 Share Posted June 16, 2008 I'm really stumped here. On index.php, there is a text input and a button. When you click the button, test.php is loaded onto index.php How would i pass along what the user wrote in the text input without refreshing the page? Thanks! index.php <script type="text/javascript"> function load_new() { document.getElementById('AfterWallPost').innerHTML = "<iframe frameborder='0' src='http://mysite/test.php'></iframe>"; } </script> <div id="AfterWallPost"> <form method="POST"> <input type="text" name="wall"> <input type="submit" value="Post Comment!" onclick="load_new()"> </div> test.php <?php echo "Cool Beans!"; $wall = "This was the Wall Post"; echo "<br> $wall "; ?> Quote Link to comment https://forums.phpfreaks.com/topic/110350-passing-information-on-same-page/ Share on other sites More sharing options...
.josh Posted June 16, 2008 Share Posted June 16, 2008 use $_POST['wall'] instead of $wall Quote Link to comment https://forums.phpfreaks.com/topic/110350-passing-information-on-same-page/#findComment-566190 Share on other sites More sharing options...
ohdang888 Posted June 16, 2008 Author Share Posted June 16, 2008 That doesn't work. The user stays on the same page and the $_POST values are not set. Maybe, i could somehow grab what was inside in the <input> via javascript? Thanks for helping! Quote Link to comment https://forums.phpfreaks.com/topic/110350-passing-information-on-same-page/#findComment-566191 Share on other sites More sharing options...
.josh Posted June 16, 2008 Share Posted June 16, 2008 if you want php to know what the user put in the form, a request has to be sent to the server, via the get or post method, and it would be accessed via the get or post array. That's your only option with php. Quote Link to comment https://forums.phpfreaks.com/topic/110350-passing-information-on-same-page/#findComment-566192 Share on other sites More sharing options...
ohdang888 Posted June 16, 2008 Author Share Posted June 16, 2008 ohhhh alright. So could i do this is javascript or ajax??? For you facebook users out there, to give you an example, its like the Facebook Profile wall. It sends your post to the server, and then displays what you wrote, without refreshing the page... and facebook is a PHP/MySQL site, so i guess they use js or ajax.. Thanks! Quote Link to comment https://forums.phpfreaks.com/topic/110350-passing-information-on-same-page/#findComment-566193 Share on other sites More sharing options...
.josh Posted June 16, 2008 Share Posted June 16, 2008 an example of this would be: index.php <form action = 'test.php' method='post'> <input type="text" name="wall"> <input type="submit" value="Post Comment!"> </form> test.php <?php if ($_POST['wall']) { echo $_POST['wall']; } ?> Yes, you can use ajax to make a request and update an element on the page without refreshing the whole page. Quote Link to comment https://forums.phpfreaks.com/topic/110350-passing-information-on-same-page/#findComment-566194 Share on other sites More sharing options...
ohdang888 Posted June 16, 2008 Author Share Posted June 16, 2008 oh i know how to handle php forms. Its just i don't want to reload the page. Yes, you can use ajax to make a request and update an element on the page without refreshing the whole page. oh ok.... i found this: http://www.boutell.com/newfaq/creating/ajaxfetch.html but it doesn't make any sense... h/o i'll try some more... Quote Link to comment https://forums.phpfreaks.com/topic/110350-passing-information-on-same-page/#findComment-566196 Share on other sites More sharing options...
.josh Posted June 16, 2008 Share Posted June 16, 2008 okay well then yes, go for some ajax. Virtually every beginner ajax tutorial shows you how to do what you wanna do, so doing a "ajax tutorial" google search will yield lots of results. Quote Link to comment https://forums.phpfreaks.com/topic/110350-passing-information-on-same-page/#findComment-566198 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.