/    Sign up×
Community /Pin to ProfileBookmark

<textarea> or <input="text"> Problem

I need to get a response from the viewer and keep it on screen for all time,
for others to see and until I physically remove it.

I have access to Mysql if required but would prefer a .txt file for storage.

If anyone can write me some code to cover the above it would be appreciated.

The displayed text does not have to remain in the same textarea, if it is
easier to display the .txt file in a scrolling box and at a different location
on the page then that’s ok.

Thanx…

[COLOR=”RoyalBlue”][I]They do say “Ignorance is Bliss” I find it a pain in the brain…[/COLOR][/I]

to post a comment
PHP

19 Comments(s)

Copy linkTweet thisAlerts:
@scragarApr 28.2007 — shouldn't be too hard, but if you want a full text file things could get a bit hard to remove...

[code=php]<?
echo "<form action='?#bottom' method=post>
<input type='text' name='message'>
<input type='submit' value='comment'>
</form>";
if(isset($_POST['message'])){
$x = fopen("messages.txt", 'a');
fwrite ($x, str_replace("n", "", $_POST['message']);
fclose($x);
echo "message posted.";
};
if(file_exists("messages.txt")){
echo "<div style='display: block; height: 500px; width: 90%; overflow: scroll'>";
$lines = file('messages.txt');
foreach ($lines as $line) {
echo htmlspecialchars($line)."<br>n";
};
echo "<a name='bottom'></a></div>";
?>[/code]
Copy linkTweet thisAlerts:
@glenvernauthorApr 28.2007 — Hi Scragar

Thanx for your response.

Unfortunately I cannot get it to work on my webpage - see

http://www.wjcag.co.uk/textboxtest.htm

Is there something that I should be doing other than just

copy and paste your text into the page.?



cheers..
Copy linkTweet thisAlerts:
@scragarApr 29.2007 — that code should and does work exactly as you requested for me, could you send me a link to your site so I can check it or at the very least the generated HTML incase somethings wrong...
Copy linkTweet thisAlerts:
@SheldonApr 29.2007 — The reason is the file extention on your textboxtest.html needs to be .php!

textboxtest.php
Copy linkTweet thisAlerts:
@scragarApr 29.2007 — could you post lines 20 - 24 of your code please, it's reporting an error for you.
Copy linkTweet thisAlerts:
@scragarApr 29.2007 — actually, I've just realized the error, I forgot to close a brace, when I tested it I must have fixed it without realizing giving you the broken one.

[code=php]<?
echo "<form action='?#bottom' method=post>
<input type='text' name='message'>
<input type='submit' value='comment'>
</form>";
if(isset($_POST['message'])){
$x = fopen("messages.txt", 'a');
fwrite ($x, str_replace("n", "", $_POST['message']);
fclose($x);
echo "message posted.";
};
if(file_exists("messages.txt")){
echo "<div style='display: block; height: 500px; width: 90%; overflow: scroll'>";
$lines = file('messages.txt');
foreach ($lines as $line) {
echo htmlspecialchars($line)."<br>n";
};
echo "<a name='bottom'></a></div>";
};
?>[/code]

anyone know why I couldn't edit my other message?
Copy linkTweet thisAlerts:
@glenvernauthorApr 30.2007 — Hi Scragar

Still can't get it to work for me.. URL =

http://www.wjcag.co.uk/textboxtest.php

I get a parse error..(unexpected comma in fwrite line)


*************
Even if I get the above to work I will only have an input text box,

I can't see the answer permanently appearing in a textarea or scrolling box.??

If you go to the following URL =

http://www.wjcag.co.uk/textboxtest2.php

you will get some idea of what I am trying to achieve..


.
Copy linkTweet thisAlerts:
@scragarApr 30.2007 — can you show me a few lines before and after the offending one(24), and I'll see if I can fix it.

as for what you want with the bottom link are you talking about just storing the info so you can look at it, or making it public so all can see?
Copy linkTweet thisAlerts:
@glenvernauthorApr 30.2007 — Yes I would like to make it public and permanent (or until I delete it)

Here's the <body> as requested...


<body>

<center>

<br><br>

<img border=1 src="http://www.wjcag.co.uk/images2/blubells.gif">

<br><br>

Dark Blue &nbsp; &nbsp; &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;

Light Blue &nbsp; &nbsp; &nbsp; &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;

Pink &nbsp; &nbsp; &nbsp; &nbsp;&nbsp;&nbsp;

White &nbsp; &nbsp; &nbsp; <br><br>

Can you identify these Bluebells please.?<br><br>

What's the difference between a Bluebell and a Harebell.?<br><br>

<?

echo "<form action='?#bottom' method=post>

<input type='text' name='message'>

<input type='submit' value='comment'>

</form>";

if(isset($_POST['message'])){

$x = fopen("messages.txt", 'a');

fwrite ($x, str_replace("n", "", $_
POST['message']);

fclose($x);

echo "message posted.";

};

if(file_exists("messages.txt")){

echo "<div style='display: block; height: 500px; width: 90%; overflow: scroll'>";

$lines = file('messages.txt');

foreach ($lines as $line) {

echo htmlspecialchars($line)."<br>n";

};

echo "<a name='bottom'></a></div>";

};

?>

</center>

</body>
Copy linkTweet thisAlerts:
@scragarApr 30.2007 — would it be safe to assume that you don't have any other PHP on that page that may be causing the error(an unclosed tag, brace, quote or a line that deserves a semicolon but doesn't get one)?
Copy linkTweet thisAlerts:
@glenvernauthorApr 30.2007 — Here you have the whole page, I can't see any open tags or misplaced punctuations..........

<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">

<html>

<head>

<meta content="text/html; charset=ISO-8859-1" http-equiv="content-type">

<title>textboxtest</title>

<link rel="stylesheet" href="http://www.wjcag.co.uk/stylesheet.css" type="text/css">

</head>

<body>

<center><br><br>

<img border=1 src="http://www.wjcag.co.uk/images2/blubells.gif">

<br><br>

Dark Blue &nbsp; &nbsp; &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;

Light Blue &nbsp; &nbsp; &nbsp; &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;

Pink &nbsp; &nbsp; &nbsp; &nbsp;&nbsp;&nbsp;

White &nbsp; &nbsp; &nbsp; <br><br>

Can you identify these Bluebells please.?<br><br>

What's the difference between a Bluebell and a Harebell.?<br><br>

<?

echo "<form action='?#bottom' method=post>

<input type='text' name='message'>

<input type='submit' value='comment'>

</form>";

if(isset($_POST['message'])){

$x = fopen("messages.txt", 'a');

fwrite ($x, str_replace("n", "", $_
POST['message']);

fclose($x);

echo "message posted.";

};

if(file_exists("messages.txt")){

echo "<div style='display: block; height: 500px; width: 90%; overflow: scroll'>";

$lines = file('messages.txt');

foreach ($lines as $line) {

echo htmlspecialchars($line)."<br>n";

};

echo "<a name='bottom'></a></div>";

};

?>

</center>

</body>

</html>
Copy linkTweet thisAlerts:
@scragarApr 30.2007 — [code=php]<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
<head>
<meta content="text/html; charset=ISO-8859-1" http-equiv="content-type">
<title>textboxtest</title>
<link rel="stylesheet" href="http://www.wjcag.co.uk/stylesheet.css" type="text/css">
<style type='text/css'>
span.usr{
color: #FF0000;
}
</style>
</head>
<body>
<center><br><br>
<img border=1 src="http://www.wjcag.co.uk/images2/blubells.gif">
<br><br>
Dark Blue &nbsp; &nbsp; &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
Light Blue &nbsp; &nbsp; &nbsp; &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; Pink &nbsp; &nbsp; &nbsp; &nbsp;&nbsp;&nbsp;
White &nbsp; &nbsp; &nbsp; <br><br>
Can you identify these Bluebells please.?<br><br>
What's the difference between a Bluebell and a Harebell.?<br><br>

<?
echo "<form action='?#bottom' method=post>
<input type='text' name='user'>
<input type='text' name='message'>
<input type='submit' value='comment'>
</form>";
if(isset($_POST['message']) && isset($_POST['user'])){
$x = fopen("messages.txt", 'a');
fwrite ($x, htmlspecialchars(str_replace("n", "", $_POST['user']))."n");
fwrite ($x, htmlspecialchars(str_replace("n", "", $_POST['message']))."n");
fclose($x);
echo "message posted.";
};
if(file_exists("messages.txt")){
echo "<div style='display: block; height: 500px; width: 90%; overflow: scroll'>";
$lines = file('messages.txt');
$i = 0;
foreach ($lines as $line) {
if($i == 0){
echo "<span class='usr'>$line</span>: n";
}else{
echo "$line<br>n";
};
$i++;
};
echo "<a name='bottom'></a></div>";
};
?>
</center>
</body>
</html>[/code]

tada, try that on for size and see what you think. you'll have to mod it slightly as needed though(appearance mostly).

TESTED AND IT WORKS!
Copy linkTweet thisAlerts:
@glenvernauthorApr 30.2007 — Tested it on the website and looking good

Need to get it into a textarea now instead of just open print on the page

I see that multiple entries are just added to the end of the previous one

need another <br> n somewhere I think
Copy linkTweet thisAlerts:
@scragarApr 30.2007 — try downloading the attachment for my latest fix(just making sure nothing stops it lol.)

and what do you meant by text area? do you mean you want the text to be displayed in a text area as opposed to the div with overflow set to on?

[upl-file uuid=baa18995-986f-412e-98ae-848b59c8742c size=2kB]blah.txt[/upl-file]
Copy linkTweet thisAlerts:
@glenvernauthorApr 30.2007 — Excellent - Game over

Many thanks, the display block works just fine no need for the textarea .

I think I will remove the first input box as it does not <br> but the second one does so I shall just use that one..


very much appreciated, thank you Scragar


.
Copy linkTweet thisAlerts:
@glenvernauthorApr 30.2007 — Unfortunately there is still one niggling problem -

no spaces or <br> between the two entries.

Keeps adding to the end of the previous entry without any spaces or line breaks. Can this be fixed?

tried adding them myself but either stops working or gives me an error

.
Copy linkTweet thisAlerts:
@scragarMay 01.2007 — this one should work by adding a username/nickname field, if you want rid of the username/nickname field forever just ask and I'll cut it out.

[upl-file uuid=01da8328-063a-45ef-92b7-028ec9d47108 size=2kB]blah.txt[/upl-file]
Copy linkTweet thisAlerts:
@glenvernauthorMay 01.2007 — Nothing further required thanx Scragar..

All working as I had hoped..
×

Success!

Help @glenvern spread the word by sharing this article on Twitter...

Tweet This
Sign in
Forgot password?
Sign in with TwitchSign in with GithubCreate Account
about: ({
version: 0.1.9 BETA 5.27,
whats_new: community page,
up_next: more Davinci•003 tasks,
coming_soon: events calendar,
social: @webDeveloperHQ
});

legal: ({
terms: of use,
privacy: policy
});
changelog: (
version: 0.1.9,
notes: added community page

version: 0.1.8,
notes: added Davinci•003

version: 0.1.7,
notes: upvote answers to bounties

version: 0.1.6,
notes: article editor refresh
)...
recent_tips: (
tipper: @AriseFacilitySolutions09,
tipped: article
amount: 1000 SATS,

tipper: @Yussuf4331,
tipped: article
amount: 1000 SATS,

tipper: @darkwebsites540,
tipped: article
amount: 10 SATS,
)...