home hardware prices news articles forums photos user reviews
Go Back   Tech Support Forums - TechIMO.com > PC Hardware and Tech > Webmastering and Programming
Ask a Tech Support Question (free)!

Web form updates a txt file

Reply
Get bargains at  »  Dealighted.com
 
Thread Tools Search this Thread
Currently Active Users: 2721
Discussions: 200,998, Posts: 2,379,979, Members: 246,367
Old January 26th, 2003, 02:17 PM   Digg it!   #1 (permalink)
Member
 
Carl-cox-'s Avatar
 
Join Date: Nov 2002
Location: Kent England
Posts: 395
Web form updates a txt file

Is there a way to automatically add to a .txt file from a web form.

If not what are the options not PHP sorry
Carl-cox- is offline   Reply With Quote
Old January 26th, 2003, 02:32 PM     #2 (permalink)
Member
 
tenor_david's Avatar
 
Join Date: Nov 2001
Location: Bloomington IN
Posts: 219
There are quite a few ways to do what you are asking, but not any that are 'automatic' as far as I know. If your server supports Perl, it is fairly easy to set this up.

Unfortunately, I am about to start teaching a class on XHTML, so I can't go into any gory details.

If not one else responds, I'll get back to this later.
tenor_david is offline   Reply With Quote
Old January 26th, 2003, 02:47 PM     #3 (permalink)
Member
 
Carl-cox-'s Avatar
 
Join Date: Nov 2002
Location: Kent England
Posts: 395
what i meant was that you add tot he text file from the webform then press submit and it will update that file ?
__________________
http://www.coxeh.com
Carl-cox- is offline   Reply With Quote
Old January 26th, 2003, 11:26 PM     #4 (permalink)
Member
 
tenor_david's Avatar
 
Join Date: Nov 2001
Location: Bloomington IN
Posts: 219
Yes, there are ways that you can have, upon form submission, an update to a text file.

Here is a very simple example:

Web Form:


<html>
<head>
<title>Simple Append Web Form</title>
</head>
<body>
<p>
<form action="addtxt.pl" method="POST">
Name: <input type="text" name="Name"><br />
Address: <input type="text" name="Address"><br />
City: <input type="text" name="City"><br />
State: <input type="text" name="State"><br />
Zip: <input type="text" name="Zip"><br />
Phone: <input type="text" name="Telephone"><br />
<input type="submit">
</form>
</p>
</body>
</html>


Perl File:


#!/usr/bin/perl

use CGI;
$query = new CGI;

open FILE, ">>data.txt" || die $!;
print FILE "=================\n";
foreach($query->param) {
print FILE $_ , '=>', $query->param($_), "\n";
}
close FILE;

print $query->header;
print $query->start_html("Thank you");
print "you may now continue browsing\n";
print $query->end_html;


Appended Text File Format:


=================
Name=>1234
Address=>65437
City=>90870
State=>ssdfg
Zip=>ytey
Telephone=>uuiuii


So, in this instance, your web form is collecting demographic info. When you submit it, the form is processed by the Perl File, which will open up data.txt and append '========' to denote a new 'record', all of the field names, a =>, and the users input, followed by a new line, close the data.txt file, and print out a message to the user.

Does that make sense?

Last edited by tenor_david : January 27th, 2003 at 12:55 AM.
tenor_david is offline   Reply With Quote
Old January 27th, 2003, 07:22 AM     #5 (permalink)
Member
 
Carl-cox-'s Avatar
 
Join Date: Nov 2002
Location: Kent England
Posts: 395
thanks for that ill try that when i get home
Carl-cox- is offline   Reply With Quote
Old January 27th, 2003, 09:52 AM     #6 (permalink)
Go back to sleep
 
Creatures's Avatar
 
Join Date: Jul 2002
Location: Switzerland
Posts: 7,389
Send a message via ICQ to Creatures
awsome thanks!
i needed something like this

Creatures
__________________
Canon EOS 450D | Canon EF-S 18-55mm 1:3.5-5.6 IS | Canon EF-S 55-250mm 1:4-5.6 IS | Canon Speedlite 430EX II
Creatures is online now   Reply With Quote
Old January 27th, 2003, 10:46 AM     #7 (permalink)
Member
 
tenor_david's Avatar
 
Join Date: Nov 2001
Location: Bloomington IN
Posts: 219
Just be aware that this is a VERY simple example. There are many other factors you may want to look into.

1) This form doesn't validate field entries. As in my example entry, a user could enter any text in the Date or Telephone fields. You could use Javascript or Perl to ensure that your fields are validated.

2) This form doesn't Parse input. Technically, everytime a field is entered, it is being saved w/ and extra space at the end. You could look into downloading cgi.lib, which contains a subroutine called ReadParse, which would remove that extra space at the end.

Perl is a really great language for all types of text manipulation and processing. I don't know THAT much, but even knowing a little amount can provide you many new utilities and functionalities.
tenor_david is offline   Reply With Quote
Old January 27th, 2003, 01:07 PM     #8 (permalink)
Member
 
Carl-cox-'s Avatar
 
Join Date: Nov 2002
Location: Kent England
Posts: 395
Thanks i got it working but i need to access text file by the browser. i cant at the moment as it is in a cgi-bin folder

is it possible to chnage the txt file under a diffrent folder becasue i tried to put teh Url in the pl file and it didnt work. is there a way round this please

open FILE, ">>http://myserver.thinggy/news.txt" || die $!;

This doesnt work as it doent update the file


Last edited by Carl-cox- : January 27th, 2003 at 01:14 PM.
Carl-cox- is offline   Reply With Quote
Old January 27th, 2003, 01:19 PM     #9 (permalink)
Member
 
tenor_david's Avatar
 
Join Date: Nov 2001
Location: Bloomington IN
Posts: 219
Did you change the permissions on the text file so that you could access it via a browser?

Or have you tried:
open FILE, ">>cgi-cin/news.txt" || die $!;
tenor_david is offline   Reply With Quote
Old January 27th, 2003, 01:37 PM     #10 (permalink)
Member
 
Carl-cox-'s Avatar
 
Join Date: Nov 2002
Location: Kent England
Posts: 395
no i havent chnaged the permission how do u do that

i added this line to try and access the txt file outside the cgi-bin folder but for some reason it doesnt update the file

open FILE, ">>http://hardtweak.netfirms.com/news.txt" || die $!;

but for the file in the cgi-bin folder i get this http://hardtweak.netfirms.com/cgi-bin/news.txt

This is why i want to chnage the code so it can update the file outside of the cgi-bin folder
Carl-cox- is offline   Reply With Quote
Reply
Thread Tools Search this Thread
Search this Thread:

Advanced Search


Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
 
Most Active Discussions
Is It Just Me? (3103)
‘Rogue’ or ‘Rouge’? (6)
Charges against non-tippers dropped.. (22)
Foxconn Blackops x48 MoBo (5)
Nvidia GTX 260 problem (14)
Delete an OS (18)
Laptop with wireless problem. (13)
Wireless Televisions. (12)
CPU fan stops spinning randomly (11)
windows vista security holes (19)
Regular Build (11)
Point and Shoot Camera Suggestions. (9)
[F@H SPAM 11/16/09] ! 1/2 months to.. (41)
windows 7 problem (7)
Recent Discussions
EVGA 9800 gtx help with finding a goo.. (13)
"Documents and Settings" fo.. (7)
Delete an OS (18)
Outputing 1080p from my PC to my 720p.. (0)
panasonic dmr ez48veb recorder (0)
add ram to existing (3)
Need help getting speakers to work (2)
Nvidia GTX 260 problem (14)
Laptop with wireless problem. (13)
Point and Shoot Camera Suggestions. (9)
Is the PSU I received dead? (16)
FreeAgent drive software not x64 comp.. (1)
Intel 5100 AGN issues fixed yet? (28)
Foxconn Blackops x48 MoBo (5)
[F@H SPAM 11/16/09] ! 1/2 months to r.. (41)
Print spooler problem (17)
Q9650 vs. Q9550 (2)
Desktop Calendar Application (2)
Looking for new motherboard (1)
soundmon.exe (8)
Jedi Academy Problem (3)
Can a page file be "too big".. (1)
Size after cutting 700Mb file is 2.5 .. (0)
windows vista security holes (19)
updating BIOS via winflash, claims fi.. (1)


All times are GMT -4. The time now is 01:05 PM.
TechIMO Copyright 2009 All Enthusiast, Inc.



1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28