Jump to content

Submit form, and it adds to a list of names.


neogrant

Recommended Posts

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

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.

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!

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?

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 :D

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?

 

<?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?

<?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.

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.