Solved

What's wrong with this ?

Posted on 2000-03-08
9
164 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
How Do You Stack Up Against Your Peers?

With today’s modern enterprise so dependent on digital infrastructures, the impact of major incidents has increased dramatically. Grab the report now to gain insight into how your organization ranks against your peers and learn best-in-class strategies to resolve incidents.

 

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

Master Your Team's Linux and Cloud Stack!

The average business loses $13.5M per year to ineffective training (per 1,000 employees). Keep ahead of the competition and combine in-person quality with online cost and flexibility by training with Linux Academy.

Question has a verified solution.

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

This tutorial will discuss fancy secure registration forms, with AJAX technology support. In this article I assume you already know HTML and some JS. I will write the code using WhizBase Server Pages, so you need to know some basics in WBSP (you mig…
This article is meant to give a basic understanding of how to use R Sweave as a way to merge LaTeX and R code seamlessly into one presentable document.
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 a recent question (https://www.experts-exchange.com/questions/29004105/Run-AutoHotkey-script-directly-from-Notepad.html) here at Experts Exchange, a member asked how to run an AutoHotkey script (.AHK) directly from Notepad++ (aka NPP). This video…

860 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