Solved

What's wrong with this ?

Posted on 2000-03-08
9
162 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
  • 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
 

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
How your wiki can always stay up-to-date

Quip doubles as a “living” wiki and a project management tool that evolves with your organization. As you finish projects in Quip, the work remains, easily accessible to all team members, new and old.
- Increase transparency
- Onboard new hires faster
- Access from mobile/offline

 
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

IT, Stop Being Called Into Every Meeting

Highfive is so simple that setting up every meeting room takes just minutes and every employee will be able to start or join a call from any room with ease. Never be called into a meeting just to get it started again. This is how video conferencing should work!

Join & Write a Comment

Suggested Solutions

This tutorial will discuss the log-in process using WhizBase. In this article I assume you already know HTML. I will write the code using WhizBase Server Pages, so you need to know some basics in WBSP (you might look at some of my other articles abo…
Batch, VBS, and scripts in general are incredibly useful for repetitive tasks.  Some tasks can take a while to complete and it can be annoying to check back only to discover that your script finished 5 minutes ago.  Some scripts may complete nearly …
The viewer will learn how to count occurrences of each item in an array.
This tutorial will teach you the core code needed to finalize the addition of a watermark to your image. The viewer will use a small PHP class to learn and create a watermark.

743 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

Need Help in Real-Time?

Connect with top rated Experts

11 Experts available now in Live!

Get 1:1 Help Now