January 26th, 2003, 02:17 PM
|
#1 (permalink)
| | Member
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 |
| |
January 26th, 2003, 02:32 PM
|
#2 (permalink)
| | Member
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. |
| |
January 26th, 2003, 02:47 PM
|
#3 (permalink)
| | Member
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 ? |
| |
January 26th, 2003, 11:26 PM
|
#4 (permalink)
| | Member
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.
|
| |
January 27th, 2003, 07:22 AM
|
#5 (permalink)
| | Member
Join Date: Nov 2002 Location: Kent England
Posts: 395
|
thanks for that ill try that when i get home |
| |
January 27th, 2003, 09:52 AM
|
#6 (permalink)
| | Go back to sleep
Join Date: Jul 2002 Location: Switzerland
Posts: 6,163
|
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 |
| |
January 27th, 2003, 10:46 AM
|
#7 (permalink)
| | Member
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. |
| |
January 27th, 2003, 01:07 PM
|
#8 (permalink)
| | Member
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.
|
| |
January 27th, 2003, 01:19 PM
|
#9 (permalink)
| | Member
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 $!; |
| |
January 27th, 2003, 01:37 PM
|
#10 (permalink)
| | Member
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 |
| | |
Currently Active Users Viewing This Thread: 1 (0 members and 1 guests) | | |
Posting Rules
| You may post new threads You may post replies You may not post attachments You may not edit your posts HTML code is Off | | | | Most Active Discussions | | | | | Recent Discussions  | | | | | |