Booooze
12-11-2003, 08:53 PM
does any1 know of a CGI script that will save input from a form to a txt file on the server?
thx
thx
|
Click to See Complete Forum and Search --> : cgi scripts Booooze 12-11-2003, 08:53 PM does any1 know of a CGI script that will save input from a form to a txt file on the server? thx Jeff Mott 12-11-2003, 09:04 PM The CGI module will do it all for you. http://www.perldoc.com/perl5.8.0/lib/CGI.html#SAVING-THE-STATE-OF-THE-SCRIPT-TO-A-FILE- Booooze 12-11-2003, 09:20 PM is there anything not as advanced and easier to install? I'm not a perl programmer. im a Vb programmer, so im not "stupid" when it comes to this stuff, but not smart either. Do you know sopmething easier? thx Jeff Mott 12-11-2003, 09:32 PM The link I gave wasn't to a full script, it was to a module that does exactly what you need, thus making the job incredibly easy.#!/usr/bin/perl use CGI; use Fcntl qw[:flock]; my $cgi = CGI->new(); open FH, '> file.txt' or die $!; flock FH, LOCK_EX or die $!; $cgi->save(FH); close FH or die $!; print $cgi->header(), $cgi->start_html(), $cgi->p('Input saved.'), $cgi->end_html() or die $!;Note: code is untested. Booooze 12-11-2003, 09:42 PM how do use this code? as i said, i dont know much about perl or cgi scripts. If this isnt a script, do you know where i can find one? thx for all the help:D much appreciated Jeff Mott 12-11-2003, 09:44 PM The link I had posted was not to a full script, but the code in my last post is a full script. You can use that. Booooze 12-11-2003, 10:01 PM you said the code was untested. ive saved that code as formsave.pl then i changed the first line to the right dir(im hosting my own site). when i use the script with a form and the asction pointing to the script and all, the scripts runs , and the "file.txt" is made, but the input from the boxes doesnt work. do i need to specify certain boxes? thank you very much! Jeff Mott 12-11-2003, 10:15 PM I just tested it myself and all the data was successfully saved. Could you elaborate some more instead of simply saying it doesn't work? Booooze 12-11-2003, 10:24 PM ok...first of all i want to thank you for all your help so far. im sure your getting frustrated. anyways, im using abyss web server to host my site on my computer. what i want to do is have the visitor input information in a <textarea> and some textboxes, then save that data to the text file on my server. i copied your code, saved it as formsave.pl . i replaced the first line of the file to match my perl directory because i have to use thrif party software to use perl scripts with this web host program. then i used the following code <html> <body> <FORM ACTION="cgi-bin/formsave.pl" METHOD=post> Your name<br> <input type=text name=name><br> Your email<br> <input type=text name=email><br> Your country<br> <input type=text name=country><br> <INPUT TYPE=submit value="Submit"> </FORM> </body> </html> the perl script is in the cgi-bin. when i run my website on another computer, then fill in the boxes, then hit submit, it gives me in internal server 500 error. but, the TXT file is created, but the data does not write to it. i am pretty sure my server settings are correct, but im am going to check them again. do you have any ideas? thanks Jeff Mott 12-11-2003, 11:26 PM Add the following line of code.use CGI::Carp qw[fatalsToBrowser];This will print Perl's error message to the browser instead of the useless 500 error message. The line can be placed pretty much anywhere within the script, but to keep things looking organized I'd recommend placing it along side the other use statements. Booooze 12-11-2003, 11:32 PM Software error: flock() unimplemented on this platform at formsave.pl line 8. For help, please send mail to this site's webmaster, giving this error message and the time and date of the error. theres the error. i think it has something to do with my server program, so ill try to fix it myself. if you have any ideas plz post them. do you know exatly what this error means? anything you can help me with? but if not, thx for all your help and ill come back if i have anymore questions thx Jeff Mott 12-12-2003, 12:16 AM Easy fix: delete the lines use Fcntl... and flock... I guessing you're running a Win 95/98/ME machine? If you want flock to be supported I think you need to upgrade to an NT based platform (WinNT, Win2k, WinXP). Booooze 12-12-2003, 08:51 PM well, its working now, thank you very much for that, but one more thing. how can i make it save to a new file each time new data is submited? every time i hit submit, my data is saved, thats fine. but if i renter more info and hit submit, it overwrites. how can i fix this? thank you Booooze 12-12-2003, 08:55 PM and, when i use a textarea, it screws up all the info. it puts in % signs and stuff. eg. %0D%0Aadsadadasda%3Chtml%3E%0D%0A%3Chead%3E%0D%0A%3Ctitle%3E%3C%2Ftitle%3E%0D%0A%3C%2Fhead%3E%0D%0A% 3Cbody%20bgcolor%3Dblack%20text%3Dred%3E%0D%0A%3Ccenter%3E%3Ch1%3E%3C%2Fh1%3E%3C%2Fcenter%3E%3Chr%3E %0D%0A%3Cform%20%3E%0D%0A%3Col%3E%0D%0A%09%3Cp%3E%0D%0A%09dsa%3Cinput%20type%3D%27text%27%20name%3D% 27answer%27%20size%3D%2730%27%3Edsadsa%09%09%3Cinput%20type%3D%27button%27%20value%3D%27Answer%27%20 onClick%3D%27alert%28%22dsa%22%29%27%3E%3Chr%3E%09%3Cp%3E%0D%0A%09%3Cp%3E%0D%0A%09%3Cp%3E%0D%0A%09%3 Cp%3E%0D%0A%09%3Cp%3E%0D%0A%09%3Cp%3E%0D%0A%09%3Cp%3E%0D%0A%09%3Cp%3E%0D%0A%09%3Cp%3E%0D%0A%09%3Cp%3 E%0D%0A%09%3Cp%3E%0D%0A%09%3Cp%3E%0D%0A%09%3Cp%3E%0D%0A%09%3Cp%3E%0D%0A%3C%2Fol%3E%0D%0A%3C%2Fform%3 E%3C%2Fbody%3E%0D%0A%3C%2Fhtml%3E how can i fix that? its a textarea. could i fix this by using a different editor? thx again Jeff Mott 12-13-2003, 11:13 AM That is because it is URL encoded. The format is not designed for a textarea, it is designed to be storable and retrievable. What method are you using to get this data into a textarea? Booooze 12-13-2003, 12:20 PM As in: <form action="cgi-bin/formsave.pl" method="post" name="form2"> this it???this is the only Method part i know of. When i use the textarea note that the stuff that i type in is html code. does this have any affect? i hope we can fix this even if it means using a different script. thank you TinRam 07-02-2006, 04:08 PM I've only just started Perl myself and have been tackling this same problem.. I'm reading the text and converting it using the s///g (switch) method. Try $textField =~ s/(%2C)/,/g; $textField =~ s/(%3F)/?/g; $textField =~ s/(%21)/!/g; $textField =~ s/(%22)/"/g; $textField =~ s/(%A3)/£/g; $textField =~ s/(%24)/\$/g; $textField =~ s/(%25)/%/g; $textField =~ s/(%5E)/^/g; $textField =~ s/(%26)/&/g; $textField =~ s/(%2A)/*/g; $textField =~ s/(%28)/(/g; $textField =~ s/(%29_)/)/g; $textField =~ s/(%2B)/_/g; $textField =~ s/(%3D)/+/g; $textField =~ s/(%7D)/}/g; $textField =~ s/(%7B)/{/g; $textField =~ s/(%5D)/]/g; $textField =~ s/(%5B)/[/g; $textField =~ s/(%7E)/~/g; $textField =~ s/(%27)/'/g; $textField =~ s/(%23)/\#/g; $textField =~ s/(%40)/@/g; $textField =~ s/(%2F)/;/g; $textField =~ s/(%3A)/:/g; $textField =~ s/(%3B)/;/g; $textField =~ s/(%3E)//g; $textField =~ s/(%3C)/>/g; $textField =~ s/(%7C)/,/g; $textField =~ s/(%5C)/</g; $textField =~ s/(%0D%0A)/<br>/g; Bare in mind that while I've tested it works I haven't checked that the right URL statement conforms to the right characters. For example, $textField =~ s/(%2C)/,/g; means 'for textField', substitute %2C with , I hope that helps. JulianJ 07-02-2006, 06:29 PM I've only just started Perl myself and have been tackling this same problem.. I'm reading the text and converting it using the s///g (switch) method. Try $textField =~ s/(%2C)/,/g; $textField =~ s/(%3F)/?/g; $textField =~ s/(%21)/!/g; $textField =~ s/(%22)/"/g; $textField =~ s/(%A3)/£/g; $textField =~ s/(%24)/\$/g; $textField =~ s/(%25)/%/g; $textField =~ s/(%5E)/^/g; $textField =~ s/(%26)/&/g; $textField =~ s/(%2A)/*/g; $textField =~ s/(%28)/(/g; $textField =~ s/(%29_)/)/g; $textField =~ s/(%2B)/_/g; $textField =~ s/(%3D)/+/g; $textField =~ s/(%7D)/}/g; $textField =~ s/(%7B)/{/g; $textField =~ s/(%5D)/]/g; $textField =~ s/(%5B)/[/g; $textField =~ s/(%7E)/~/g; $textField =~ s/(%27)/'/g; $textField =~ s/(%23)/\#/g; $textField =~ s/(%40)/@/g; $textField =~ s/(%2F)/;/g; $textField =~ s/(%3A)/:/g; $textField =~ s/(%3B)/;/g; $textField =~ s/(%3E)//g; $textField =~ s/(%3C)/>/g; $textField =~ s/(%7C)/,/g; $textField =~ s/(%5C)/</g; $textField =~ s/(%0D%0A)/<br>/g; Bare in mind that while I've tested it works I haven't checked that the right URL statement conforms to the right characters. For example, $textField =~ s/(%2C)/,/g; means 'for textField', substitute %2C with , I hope that helps. Well, you could do that. Or you could just do this $string =~ s/%([a-fA-F0-9]{2})/chr(hex($1))/ge; or use URI::Escape; $str = uri_unescape($myEncodedString); Julian Booooze 07-03-2006, 01:42 AM Way to dig up a post 3 years old :cool: TinRam 07-03-2006, 07:58 AM well its still being read by folk who want tips relevant to the string. Mind you, my rediculously long convertion has been very nicely cut down for me. Well, I did say I was new to this. I know I'm writing novels to achieve what other people do in a sentence but I don't know how else to learn. Thanks for the improved code. Boozer, did you ever finnish you script? webdeveloper.com
Copyright Internet.com Inc., All Rights Reserved. |