Still celebrating National IT Professionals Day with 3 months of free Premium Membership. Use Code ITDAY17

x
?
Solved

What's wrong with this ?

Posted on 2000-03-08
9
Medium Priority
?
169 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
Python: Series & Data Frames With Pandas

Learn the basics of Python’s pandas library of series & data frames and how we can use these tools for data manipulation.

 

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 260 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

Free Tool: Port Scanner

Check which ports are open to the outside world. Helps make sure that your firewall rules are working as intended.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

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

This article will show, step by step, how to integrate R code into a R Sweave document
In threads here at EE, each comment has a unique Identifier (ID). It is easy to get the full path for an ID via the right-click context menu. However, we often want to post a short link within a thread rather than the full link. This article shows a…
Learn how to match and substitute tagged data using PHP regular expressions. Demonstrated on Windows 7, but also applies to other operating systems. Demonstrated technique applies to PHP (all versions) and Firefox, but very similar techniques will w…
In this seventh video of the Xpdf series, we discuss and demonstrate the PDFfonts utility, which lists all the fonts used in a PDF file. It does this via a command line interface, making it suitable for use in programs, scripts, batch files — any pl…

722 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