Jump to content

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.

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/

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • 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.