Solved

What's wrong with this ?

Posted on 2000-03-08
9
167 Views
Last Modified: 2013-12-25
#!/usr/local/bin/perl
print "Content-type: text/HTML\n\n";

sub EMAILME {
print <<"EOF";
<font size=2 color=black>
<B>Please you're e-mail adress
<P align="center"><input name=EMAIL type=text size=30>
</P></font>
<input type=submit value="Go and check">
</form>
EOF
}

sub checkform {
print "this is a test";
}

If I check this script and i click on 'go and check' it doesn't do a thing. Also I would like to get the 'this is a test' sentence on the same page as where the form resides.
0
Comment
Question by:saskia
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 4
  • 4
9 Comments
 
LVL 1

Expert Comment

by:stephenblade
ID: 2598374
Here is your cgi rewritten correctly:
Make sure to insert your URL where needed.

#!/usr/bin/perl
#Get the info from the form
&get_form_data;

#Did the user submit a form?
if($form{'EMAIL'} ne ""){ &checkform; }
else {

#didn't send the form so print html page

&EMAILME;
     }

sub checkform {
print "This is a test";
print "<br> Your email is $form{'EMAIL'}";
 
             }


sub EMAILME {
print <<"EOF";


<form action = "http://somesite.com/cgi-bin/some.cgi" method = "post">



<font size=2 color=black>
<B>Please you're e-mail adress
<P align="center"><input name=EMAIL type=text size=30>
</P></font>
<input type=submit value="Go and check">
</form>
EOF
}



##############################################
# Sub: Get Form Data
# This gets data from a post.

sub get_form_data {
      $buffer = "";
      read(STDIN, $buffer, $ENV{'CONTENT_LENGTH'});
      @pairs=split(/&/,$buffer);
      foreach $pair (@pairs)
      {
            @a = split(/=/,$pair);
            $name=$a[0];
            $value=$a[1];
            $value =~ s/\+/ /g;
            $value =~ s/%([a-fA-F0-9][a-fA-F0-9])/pack("C", hex($1))/eg;
            $value =~ s/~!/ ~!/g;
            $value =~ s/[\n\r]/ /sg;  #remove \n
            $value =~ s/\[\]//g;  #remove []
            push (@data,$name);
            push (@data, $value);
      }
      %form=@data;
      %form;
}

###END OF CODE ###
0
 

Author Comment

by:saskia
ID: 2601706
I'm getting a Error 500, but I can't find the error in the script. Also I would like to know what the sub Get Form Data exactly does.


#!/usr/local/bin/perl
&get_form_data;

if($form{'EMAIL'} ne ""){&checkform}
else {
&EMAILME;
}

sub checkform {
print "This is a test";
print "<br> Your email is $form{'EMAIL'}";
}


sub EMAILME {
print <<"EOF";
<form action = "../cgi-bin/tst2.cgi" method = "post">
<font size=2 color=black>
<B>Please you're e-mail adress
<P align="center"><input name=EMAIL type=text size=30>
</P></font>
<input type=submit value="Go and check">
</form>
EOF
}

sub get_form_data {
$buffer = "";
read(STDIN, $buffer, $ENV{'CONTENT_LENGTH'});
@pairs=split(/&/,$buffer);
foreach $pair (@pairs)
{
@a = split(/=/,$pair);
$name=$a[0];
$value=$a[1];
$value =~ s/\+/ /g;
$value =~ s/%([a-fA-F0-9][a-fA-F0-9])/pack("C", hex($1))/eg;
$value =~ s/~!/ ~!/g;
$value =~ s/[\n\r]/ /sg;
$value =~ s/\[\]//g;
push (@data,$name);
push (@data, $value);
}
%form=@data;
%form;
}
0
 
LVL 1

Expert Comment

by:stephenblade
ID: 2601838
sorry typo change this line



if($form{'EMAIL'} ne ""){&checkform;}

Forgot the semicolon after the checkform.

The get_form_data sub breaks down the form information that was submitted to the script so that you can use it as so:

$form{'EMAIL'} or
$form{'NAME'}  or whatever you placed in the form as in your form you placed a field called EMAIL so $form{'EMAIL'} would contain whatever they placed inside the email box. Or if you made a field called Address then $form{'Address'} would contain what they put into the Address box etc...

The lines

if($form{'EMAIL'} ne ""){&checkform}
else {
&EMAILME;
}

Check to see if the EMAIL field was filled in then takes the appropriate action.

 
0
The Ultimate Checklist to Optimize Your Website

Websites are getting bigger and complicated by the day. Video, images, custom fonts are all great for showcasing your product/service. But the price to pay in terms of reduced page load times and ultimately, decreased sales, can lead to some difficult decisions about what to cut.

 

Author Comment

by:saskia
ID: 2602064
Ok, I understand how it works. But there is still a bug in the form, cause I still get the 500 error. (I've added the semicolon)
0
 
LVL 1

Accepted Solution

by:
stephenblade earned 65 total points
ID: 2602300
OK tested it this time.. try it now..


#!/usr/bin/perl

print "Content-type: text/html\n\n";

&get_form_data;

if($form{'EMAIL'} ne ""){&checkform;}
else {
&EMAILME;
}

sub checkform {
print "This is a test";
print "<br> Your email is $form{'EMAIL'}";
}


sub EMAILME {

print <<"EOF";

<form action = "../cgi-bin/tst2.cgi" method = "post">
<font size=2 color=black>
<B>Please you're e-mail adress
<P align="center"><input name=EMAIL type=text size=30>
</P></font>
<input type=submit value="Go and check">
</form>

EOF

}

sub get_form_data {
$buffer = "";
read(STDIN, $buffer, $ENV{'CONTENT_LENGTH'});
@pairs=split(/&/,$buffer);
foreach $pair (@pairs)
{
@a = split(/=/,$pair);
$name=$a[0];
$value=$a[1];
$value =~ s/\+/ /g;
$value =~ s/%([a-fA-F0-9][a-fA-F0-9])/pack("C", hex($1))/eg;
$value =~ s/~!/ ~!/g;
$value =~ s/[\n\r]/ /sg;
$value =~ s/\[\]//g;
push (@data,$name);
push (@data, $value);
}
%form=@data;
%form;
}
0
 

Expert Comment

by:oostwijk
ID: 2613146
Thanks for helping me out !! You can get 15 extra points if you can tell me if the lines you gave me in the sub get_form_data do the same job as in these lines :

&get_form_data; # parse arguments from post
@ARGV = split(/\\*\&/, $ENV{'QUERY_STRING'});
$ARGV[0] =~ s/\W//g;
$ARGV[1] =~ s/\D//g;
if ($form{'action'} eq 'Test') { &procTest; }

I've got these lines in my current script and I'm wandering if I need to merge or delete these lines if I want to use that sub next to it.
0
 
LVL 1

Expert Comment

by:stephenblade
ID: 2613479

No actually those lines break up the arguments following the url ie.

yoururl.com/my.cgi?data1&data2&data3

the line you showed


@ARGV = split(/\\*\&/, $ENV{'QUERY_STRING'});


Split the everything after the url
and place them into the following

$ARGV[0] = data1
$ARGV[1] = data2  etc...



the lines
$ARGV[0] =~ s/\W//g;
$ARGV[1] =~ s/\D//g;

remove anything that is not a letter or a number



0
 

Author Comment

by:saskia
ID: 2613899
Adjusted points to 65
0
 

Author Comment

by:saskia
ID: 2613900
Thank you very much, keep up the good work.
0

Featured Post

What Is Transaction Monitoring and who needs it?

Synthetic Transaction Monitoring that you need for the day to day, which ensures your business website keeps running optimally, and that there is no downtime to impact your customer experience.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

I hope you'll find this tutorial useful and interesting. So let's try to extend Tcl with a new package.  For anyone more deeply interested please check out the book "Practical Programming in Tcl and Tk". It's really one of the best written books abo…
It is a general practice to get rid of old user profiles on a computer  in a LAN environment. As I have been working with a company in a LAN environment where users move from one place to some other place at times. This will make many user profil…
Learn the basics of modules and packages in Python. Every Python file is a module, ending in the suffix: .py: Modules are a collection of functions and variables.: Packages are a collection of modules.: Module functions and variables are accessed us…
In this fourth video of the Xpdf series, we discuss and demonstrate the PDFinfo utility, which retrieves the contents of a PDF's Info Dictionary, as well as some other information, including the page count. We show how to isolate the page count in a…

734 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question