home hardware prices news articles forums photos user reviews
Go Back   Tech Support Forums - TechIMO.com > PC Hardware and Tech > Webmastering and Programming
Join TechIMO for Free!
Register Blogs FAQ Members List Calendar Search Today's Posts Mark Forums Read
Reply Get bargains at  »  Dealighted.com
 
Thread Tools
Currently Active Users: 2727
Discussions: 188,385, Posts: 2,243,517, Members: 232,615
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: 6,163
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


Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
 
Thread Tools

Posting Rules
You may post new threads
You may post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are Off
Pingbacks are On
Refbacks are Off

Most Active Discussions
Is It Just Me? (2899)
CPU wont boot (7)
3-days in and no threads about Gaza (160)
I think I just killed my computer w.. (24)
hp compaq nc6000 problems (139)
Upgrading RAM (5)
Folderchat Weekday thread (442)
Antec 300 bulk purchase? (11)
Worth the upgrade?? (15)
Recent Discussions
New Build ( Finally ) (3)
CPU wont boot (7)
Problem With LightScribe DVD Dr.. (0)
GLaDOS is up. (3)
HP notebook reinstall Vista NO .. (5)
Building a gaming computer advi.. (4)
hp compaq nc6000 problems (139)
Folderchat Weekday thread (442)
Creative T-3000 Subwoofer (3)
Blackberry Storm, Gears of War .. (1)
Core 2 Quad Q9550 system (3)
COWBOOM Ripoff! Used Laptop w/$.. (4)


All times are GMT -4. The time now is 11:14 PM.
TechIMO Copyright 2008 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