Solved

What's wrong with this ?

Posted on 2000-03-08
9
166 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
MIM Survival Guide for Service Desk Managers

Major incidents can send mastered service desk processes into disorder. Systems and tools produce the data needed to resolve these incidents, but your challenge is getting that information to the right people fast. Check out the Survival Guide and begin bringing order to chaos.

 

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

MIM Survival Guide for Service Desk Managers

Major incidents can send mastered service desk processes into disorder. Systems and tools produce the data needed to resolve these incidents, but your challenge is getting that information to the right people fast. Check out the Survival Guide and begin bringing order to chaos.

Question has a verified solution.

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

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…
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…
The viewer will learn the basics of jQuery, including how to invoke it on a web page. Reference your jQuery libraries: (CODE) Include your new external js/jQuery file: (CODE) Write your first lines of code to setup your site for jQuery.: (CODE)
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…

738 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