
codywood
Novice
Nov 30, 2004, 9:33 AM
Post #1 of 13
(1255 views)
|
|
html forms and text replacement
|
Can't Post
|
|
Hey, I am VERY new to perl, in fact I am working on my first script. I am wanting to fix contractions by changing "dont" to "don't" etc. I am submitting a string of text via html forms. My end goal is to have a webpage with two text boxes. In the top box, is where I want the user to enter their paragraph of text, and the bottom box will contain the output of the the form (after submitting) as well as a tag saying where it was processed. (i.e. Fixed by The Contraction Corrector By Cody Wood http://www.sitelinkurl.com) However, I cant seem to find any info on how to do this. I have the basic mechanics down on how to replace the text, but am having problems with the output. I know I will have to include a form into the script somehow. Any help would be greatly appreciated. html form: <html> <head> <title>Contractions</title> </head> <body> <form action="http://164.58.187.228/cgi-bin/contract.cgi" method="POST" name="Contraction Correction"> <p><textarea rows="15" name="input" cols="63" maxlength="250">Enter text to be fixed here.</textarea></p> <p> </p> <p><textarea rows="15" name="output" cols="63">The Contraction Correction By Cody Wood http://www.comingsoon.com/</textarea></p> <p><input type="submit" value=" submit " name="submit"><input type="reset" value="Reset" name="Reset"></p> </form> </body> </html> cgi: #!C:\Perl\bin\perl #=============================== # Contraction Correction # Copyright 2004, Cody D. Wood # Created 11/19/04 #=============================== print "Content-type: text/html\n\n"; if($ENV{'REQUEST_METHOD'} eq "GET"){ $my_data = $ENV{'QUERY_STRING'}; } else { $data_length = $ENV{'CONTENT_LENGTH'}; $bytes_read = read(STDIN, $my_data, $data_length); } # Load it into something we can use @name_value_array = split(/&/, $my_data); # Here's where we do the actual work. We cycle # through @name_value_array to decode the name=value pairs foreach $name_value_pair (@name_value_array) { # Split the name=value pair in your HTML form data ($name, $value) = split(/=/, $name_value_pair); # Now, replace '+' with ' ' $name =~ tr/+/ /; $value =~ tr/+/ /; # separating below here. Just have a couple for example. $value =~ s/dont /don't /g; $value =~ s/wont /won't /g; $value =~ s/wouldnt /wouldn't /g; # end of the separate # Next, translate any hex values back into characters $name =~ s/%(..)/pack("C",hex($1))/eg; $value =~ s/%(..)/pack("C",hex($1))/eg; # Finally, load the variables into an associative array # so we can use it when we need it. if($form_data{$name}) { $form_data{$name} .= "\t$value"; } else { $form_data{$name} = $value; } } # Now this is where I am stuck, so I am just displaying it. foreach $form_data_key (keys(%form_data)) { print "$form_data_key = $form_data{$form_data_key}<br>"; } #=============================== #===============================
|