neogrant Posted July 5, 2010 Share Posted July 5, 2010 I want to create a simple form ==== Name ==== And want that to update real time onto the same page, so i end up with a list of names (after submission of the form) Try searching, but still learning. Any help appreciated. Found your site via google and registered because it seemed the most active. Thanks again Quote Link to comment https://forums.phpfreaks.com/topic/206798-submit-form-and-it-adds-to-a-list-of-names/ Share on other sites More sharing options...
phpSensei Posted July 5, 2010 Share Posted July 5, 2010 This question should be in the AJAX forum. Quote Link to comment https://forums.phpfreaks.com/topic/206798-submit-form-and-it-adds-to-a-list-of-names/#findComment-1081511 Share on other sites More sharing options...
jcbones Posted July 5, 2010 Share Posted July 5, 2010 To do it via PHP, something like this should work. <?php if(isset($_POST['submit'])) { //execute only if an item is posted. $name = preg_replace('~([^a-zA-Z])~','',$_POST['name']) . "\n"; //strip out all but alpha characters in the posted name. $file = fopen('names.txt','a'); //open file('names.txt') or create if it doesn't exist. fwrite($file,$name); //write the name to the end of the file. fclose($file); //close the file. } echo implode('<br />',file('names.txt')); //print the contents to the page, one name per line. ?> <form action="" method="post"> <label>Name: </label><br /> <input type="text" name="name" value="" /><br /> <input type="submit" name="submit" value=" Submit " /> </form> *modified for newline. Quote Link to comment https://forums.phpfreaks.com/topic/206798-submit-form-and-it-adds-to-a-list-of-names/#findComment-1081551 Share on other sites More sharing options...
neogrant Posted July 5, 2010 Author Share Posted July 5, 2010 To do it via PHP, something like this should work. <?php if(isset($_POST['submit'])) { //execute only if an item is posted. $name = preg_replace('~([^a-zA-Z])~','',$_POST['name']) . "\n"; //strip out all but alpha characters in the posted name. $file = fopen('names.txt','a'); //open file('names.txt') or create if it doesn't exist. fwrite($file,$name); //write the name to the end of the file. fclose($file); //close the file. } echo implode('<br />',file('names.txt')); //print the contents to the page, one name per line. ?> <form action="" method="post"> <label>Name: </label><br /> <input type="text" name="name" value="" /><br /> <input type="submit" name="submit" value=" Submit " /> </form> *modified for newline. If i could give you rep i would, thanks a lot! Quote Link to comment https://forums.phpfreaks.com/topic/206798-submit-form-and-it-adds-to-a-list-of-names/#findComment-1081578 Share on other sites More sharing options...
phpSensei Posted July 5, 2010 Share Posted July 5, 2010 haha OP i completely misunderstood there, sorry about that. And want that to update real time onto the same page, so i end up with a list of names (after submission of the form) I thought you said you wanted to do this real-time onto the same page? Quote Link to comment https://forums.phpfreaks.com/topic/206798-submit-form-and-it-adds-to-a-list-of-names/#findComment-1081581 Share on other sites More sharing options...
neogrant Posted July 5, 2010 Author Share Posted July 5, 2010 haha OP i completely misunderstood there, sorry about that. And want that to update real time onto the same page, so i end up with a list of names (after submission of the form) I thought you said you wanted to do this real-time onto the same page? That seems fine what we have right now..just another one for your tests http://webisol.com/xwis/submit/ What is entered into the form i have here.. Is it possible to make those names click able links by the names that are in this website? http://xwis.net/ra2/players/ So e.g We have neogrant on the list here, but i want a link on that profile http://xwis.net/ra2/players/neogrant/ I'm guessing it needs http://xwis.net/ra2/players/$name? Quote Link to comment https://forums.phpfreaks.com/topic/206798-submit-form-and-it-adds-to-a-list-of-names/#findComment-1081638 Share on other sites More sharing options...
phpSensei Posted July 5, 2010 Share Posted July 5, 2010 You got it, just use the $name variable Quote Link to comment https://forums.phpfreaks.com/topic/206798-submit-form-and-it-adds-to-a-list-of-names/#findComment-1081640 Share on other sites More sharing options...
neogrant Posted July 5, 2010 Author Share Posted July 5, 2010 <?php if(isset($_POST['submit'])) { //execute only if an item is posted. $name = preg_replace('~([^a-zA-Z])~','',$_POST['name']) . "\n"; //strip out all but alpha characters in the posted name. $file = fopen('names.txt','a'); //open file('names.txt') or create if it doesn't exist. fwrite($file,http://xwis.net/ra2/players/$name); //write the name to the end of the file. fclose($file); //close the file. } echo implode('<br />',file('names.txt')); //print the contents to the page, one name per line. ?> <form action="" method="post"> <label>Name: </label><br /> <input type="text" name="name" value="" /><br /> <input type="submit" name="submit" value=" Submit " /> </form> hmm havn't quite got it, where have i gone wrong? Quote Link to comment https://forums.phpfreaks.com/topic/206798-submit-form-and-it-adds-to-a-list-of-names/#findComment-1081643 Share on other sites More sharing options...
phpSensei Posted July 6, 2010 Share Posted July 6, 2010 <?php if(isset($_POST['submit'])) { //execute only if an item is posted. $name = preg_replace('~([^a-zA-Z])~','',$_POST['name']) . "\n"; //strip out all but alpha characters in the posted name. $file = fopen('names.txt','a'); //open file('names.txt') or create if it doesn't exist. fwrite($file,http://xwis.net/ra2/players/$name); //write the name to the end of the file. fclose($file); //close the file. } echo implode('<br />',file('names.txt')); //print the contents to the page, one name per line. ?> <form action="" method="post"> <label>Name: </label><br /> <input type="text" name="name" value="" /><br /> <input type="submit" name="submit" value=" Submit " /> </form> hmm havn't quite got it, where have i gone wrong? The data your putting into the text file has to be in quotations.. fwrite($file,"<a href='http://xwis.net/ra2/players/$name'>".$name."</a>"); //write the name to the end of the file. Quote Link to comment https://forums.phpfreaks.com/topic/206798-submit-form-and-it-adds-to-a-list-of-names/#findComment-1081648 Share on other sites More sharing options...
neogrant Posted July 6, 2010 Author Share Posted July 6, 2010 Hmm the links are then given <br> at the end? Quote Link to comment https://forums.phpfreaks.com/topic/206798-submit-form-and-it-adds-to-a-list-of-names/#findComment-1081656 Share on other sites More sharing options...
neogrant Posted July 6, 2010 Author Share Posted July 6, 2010 Tried to work it out but to no avail Quote Link to comment https://forums.phpfreaks.com/topic/206798-submit-form-and-it-adds-to-a-list-of-names/#findComment-1081952 Share on other sites More sharing options...
phpSensei Posted July 6, 2010 Share Posted July 6, 2010 Hmm the links are then given <br> at the end? What do you mean? Quote Link to comment https://forums.phpfreaks.com/topic/206798-submit-form-and-it-adds-to-a-list-of-names/#findComment-1082131 Share on other sites More sharing options...
neogrant Posted July 6, 2010 Author Share Posted July 6, 2010 Hmm the links are then given <br> at the end? What do you mean? When you type a nickname and submit it, you end up with a clicky link like so : http://xwis.net/ra2/players/neogrant%3Cbr%20/%3E instead of http://xwis.net/ra2/players/neogrant/ Quote Link to comment https://forums.phpfreaks.com/topic/206798-submit-form-and-it-adds-to-a-list-of-names/#findComment-1082138 Share on other sites More sharing options...
neogrant Posted July 7, 2010 Author Share Posted July 7, 2010 bump Quote Link to comment https://forums.phpfreaks.com/topic/206798-submit-form-and-it-adds-to-a-list-of-names/#findComment-1082691 Share on other sites More sharing options...
phpSensei Posted July 8, 2010 Share Posted July 8, 2010 bump Hey sorry I have been a little sick lately... can you show me your txt file where you store the entries? Quote Link to comment https://forums.phpfreaks.com/topic/206798-submit-form-and-it-adds-to-a-list-of-names/#findComment-1082917 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.