PDA

View Full Version : reading file contents into a textarea


g00fy
02-09-2003, 06:34 AM
hi all,

the subject explains it all :)

i have written a subscribe me form (after many hours of coffee and a very steep learning curve):)

what i want to do now is add a button that looks to another script and reads the contents of the file line by line into a textarea.

** is this the right approach to open another script or should i do it all from the one ?

** if it is not the right way, how do i call a part of the script when i click the button ?

here is the form code i have:

<form action="show_sub.pl" method="post" name="email_butt" id="email_butt">
<input type="submit" name="Submit" value="Show Subscribers">
</form>
<textarea name="address" cols="50" rows="10" wrap="OFF" id="address"></textarea>


and the code so far in show_sub.pl:

$memberinfo = "/a dir";
open (DAT,"<$memberinfo/address.txt");
@database_array = <DAT>;
close(DAT);
print "<textarea rows=10 cols=50>";
foreach $line (@database_array)
{
print "$line";
}
print "</textarea>";


this is where i get a server error, when i click the button to read the contents into the textarea :(

would love some direction here and i will have finished my first script with a lot of learning :D


thanx to all

g00fy

g00fy
02-09-2003, 07:36 AM
this is my second attemp but i still get server error :(


<form action="&addresses" method="post" name="email_butt" id="email_butt">
<input type="submit" name="Submit" value="Show Subscribers">
</form>



sub addresses{
open (ADDR,"<$memberinfo/address.txt");
@addr = <ADDR>;
close(ADDR);
print <textarea name="address" cols="50" rows="10" wrap="OFF" id="address">
foreach $line (@addr)
{
print "$line";
}
print </textarea>
}



to make it clearer i would like the textarea on the same page as everything else not to open a new page with the textarea, i think thats the prob with this approach


regards,

g00fy

benastan
02-17-2003, 04:11 AM
ill help ya fosho, but theres onthign u might want to thing about in ur script, it should automatically include the line breaks in the variable if u just do:

open (FILE, "<filename.extension");
flock (FILE, 2); #file locking helps sometimes you should do it
$variable = <FILE>;
close (FILE);

print $variable;


if the file said

monkeys are
really fun to play with!!

the variable would say

monkeys are
really fun to play with!!

this i think is what should happen...

anyway... try that and ill b back with wat u were asking!!


just a note, ur gonna have to use some javascript prob!!

im gonna try not to tho, they dont interchange too well...

benastan
02-17-2003, 04:26 AM
nvm that im just stupid, give me a sec and ill have the script

benastan
02-17-2003, 04:36 AM
HERES UR SCRIPT!!::

#!/usr/local/bin/perl

open (FILE, "<text.html");
flock (FILE, 2);
@file = <FILE>;
close (FILE);

print "Content-type: text/html\n\n";
print "<textarea rows=\"10\" cols=\"50\">";
$x = 0;
foreach (@file) {
print "$file[$x]";
$x += 1;
};
print "\<\/textarea>";


i tested it and it worked!