Need a CGI script to make a file
I need a Perl CGI script that will take a number of parameters, create a record with each parameter as one field on the record (comma delimited), and write it out to a plain text ASCII file on my server. Then, with each new call to the CGI, a new record is appended to the end of the file. To clear the file I'll just upload a blank file with the same name.
I'm sure it's easy to do. If someone could point me at a simple CGI example of this I could probably take it from there.
Much thanks in advance!
------------------
ArtsNFlies.com
"It's not really a flyfishing shop, more like a Martha Stewart goes fishing thing!"
Original art, hand tied flies, unique books and gifts, free sweepstakes and MORE!
Come see what everyone is talking about!
[This message has been edited by Jaiem (edited 19 January 2000).]
Rob Pengelly posted this at 22:59 — 19th January 2000.
They have: 850 posts
Joined: Jul 1999
What parameters do you want? (name, email etc?)
And will they be inputed by an html form?
------------------
A cow produces about 65 pounds of crap a day.
[This message has been edited by robp (edited 19 January 2000).]
http://www.thehungersite.com - http://www.therainforestsite.com
http://www.ratemymullet.com - Beauty is only mullet deep.
Jaiem posted this at 14:14 — 20th January 2000.
They have: 1,191 posts
Joined: Apr 1999
Rob - On my sweepstakes page I currently use a form-email CGI script to take all the info the visitor enters on the HTML page, format a letter that is emailed to the visitor as a confirmation and BCC'd to me for the entry. I believe the form-email CGI just reads the canned letter and does a search&replace based on the variable names in the HTML and the letter body. Then the CGI redirects the visitor to another page after sending the email (that's a feature I still must have!)
Instead, I want to just append all those fields to a comma delimited ASCII file. Then redirect the visitor to another page.
Take a look at the sweepstakes page on my site. Infact, put in an entry and see how it works now.
My idea is to have a "generic" Perl CGI script that takes say 30 or 40 alphanumeric form parameters (i.e. param1, param2, param3, etc.), ideally as form variables instead of actual parameters on the CGI command line, and appends them all as one comma delimited record to an ASCII file on my server. Today's system date (in the format YYYYMMDD) would always be the first field on each record. It would be great if each parameter could be left justified (i.e. remove any spaces after the right most character). Any unused (blank) parameters are considered spaces when written out to the ASCII file.
For example, a set of records would look like:
20000120,James Kirk,Somewhere,NY,etc.,etc.,,,,
20000121,Mary Jane,Nowhere,NJ,etc.,etc.,,,,
20000122,Tom Hanks,Hollywood Springs,CA,etc.,etc.,,,,,
Thus, when used, each time a visitor to my site enters the sweepstakes thier info is appended to a variable length comma delimited record on an ASCII file. Then the CGI script redirects the visitor to an HTML page I will make that thanks the person for thier entry (you'll see what I mean when you enter the sweepstakes).
I figure 30 or 40 variables would give me plenty of room to expand if I want to increase the number of questions I ask or if I want to use the script for something else later.
Thanks for your help!!
------------------
ArtsNFlies.com
"It's not really a flyfishing shop, more like a Martha Stewart goes fishing thing!"
Original art, hand tied flies, unique books and gifts, free sweepstakes and MORE!
Come see what everyone is talking about!
[This message has been edited by Jaiem (edited 20 January 2000).]
[This message has been edited by Jaiem (edited 20 January 2000).]
[This message has been edited by Jaiem (edited 20 January 2000).]
Rob Pengelly posted this at 04:04 — 21st January 2000.
They have: 850 posts
Joined: Jul 1999
Well, here is what I have done.
In the script, you specify how many elements there are in your form. Than in your html form, for each input you use
<input name="element1" ....>
<input name="element2" ...>
etc etc
I also added a feature that you did not mention, but may come in handy. You can specify that input boxes must not be left blank.
so if you wanted element1 and element5 not to be blank, you would edit the @required variable and put
@required=(1,5);
Here is a test page http://dlo.net/~rob/cgi-bin/artnfiles.html
I made it so that your first name and last name are required. If one of them is not entered, it will not go through with the script.
Here is the source http://dlo.net/~rob/cgi-bin/artnfiles.txt
Hope that helps.
------------------
A cow produces about 65 pounds of crap a day.
http://www.thehungersite.com - http://www.therainforestsite.com
http://www.ratemymullet.com - Beauty is only mullet deep.
Jaiem posted this at 13:32 — 21st January 2000.
They have: 1,191 posts
Joined: Apr 1999
Wow! Thanks a ton!
One point: Can you add the system date to the record? IOW, make the system date (format YYYYMMDD) as always the first field on the record before any of the elements?
Again, much thanks!
------------------
ArtsNFlies.com
"It's not really a flyfishing shop, more like a Martha Stewart goes fishing thing!"
Original art, hand tied flies, unique books and gifts, free sweepstakes and MORE!
Come see what everyone is talking about!
Rob Pengelly posted this at 14:34 — 21st January 2000.
They have: 850 posts
Joined: Jul 1999
Done.
------------------
A cow produces about 65 pounds of crap a day.
Jaiem posted this at 19:48 — 21st January 2000.
They have: 1,191 posts
Joined: Apr 1999
Great! Thanks again. I'll test it this weekend.
------------------
ArtsNFlies.com
"It's not really a flyfishing shop, more like a Martha Stewart goes fishing thing!"
Original art, hand tied flies, unique books and gifts, free sweepstakes and MORE!
Come see what everyone is talking about!
Jaiem posted this at 04:14 — 24th January 2000.
They have: 1,191 posts
Joined: Apr 1999
I tested it out. Works good. This will save me a heck of a lot of time!
Thanks again!
------------------
ArtsNFlies.com
"It's not really a flyfishing shop, more like a Martha Stewart goes fishing thing!"
Original art, hand tied flies, unique books and gifts, free sweepstakes and MORE!
Come see what everyone is talking about!
Rob Pengelly posted this at 16:02 — 13th February 2000.
They have: 850 posts
Joined: Jul 1999
Not sure if anyone is interested, but I added another feature to it
You can now have the input written to a file and/or have the input emailed to you.
I also renamed the file. Here is the link to the test form/info page http://dlo.net/~rob/cgi-bin/formhandler.shtml
And here is the source:http://dlo.net/~rob/cgi-bin/formhandler.txt
Anyone else suggest other features ?
------------------
Windmills always turn counter-clockwise. Except for the windmills in Ireland.
http://www.thehungersite.com - http://www.therainforestsite.com
http://www.ratemymullet.com - Beauty is only mullet deep.
Want to join the discussion? Create an account or log in if you already have one. Joining is fast, free and painless! We’ll even whisk you back here when you’ve finished.