Connecting Tech Pros Worldwide Forums | Help | Site Map

CGI - Accessing form parameters broken

Newbie
 
Join Date: Feb 2007
Posts: 3
#1: Feb 15 '07
Hello,

I found this site to be very helpful in learning perl, but now I seem to be stumped and wonder if one of experts could assit me with this little problem....

On my web form I have a simple comment form which passes 4 vars to the perl script.

from the script I get mixed up variables (weird) All variables are dumped into the first? Any Ideas what could be the problem.... ? (Using cgi.pm for this....)

____ The Perl Script_______

Expand|Select|Wrap|Line Numbers
  1. #!E:\Perl\bin\perl.exe
  2.     use CGI qw/:standard/;
  3.     use CGI::Carp qw(warningsToBrowser fatalsToBrowser);
  4.     use Net::SMTP; 
  5.     my $in = CGI::new;
  6.  
  7. # Get Vars from htm form
  8. my $Contact_me = $in->param('enable');
  9. my $Employee = $in->param('name');
  10. my $Purposal = $in->param('Purpuse');
  11. my $Comments = $in->param('Wisdom');
  12.  
  13. # message format building phase
  14. $body = "<html><HEAD><TITLE>Post Comment</TITLE></head><body><p>";
  15. $body .= "<font color=blue size=2> Web User wishs to make $Purposal . <br>";
  16. $body .= "Name: $Employee <br>"; 
  17. $body .= "User $Contact_me to be contacted. <br> ";
  18. $body .= " <br> <br> $Comments ";
  19. $body .= "<br>";
  20. $body .= "<font size=1 color=white> $ENV{REMOTE_ADDR} </font><br>";
  21. $body .= "<H6> Have a nice day!! </H6> \n";
  22. $body .= "</BODY></html> \n";   
  23.  
  24. #Test lines begin
  25. print $body;


_____HTML output from the CGI_____

[HTML]Web User wishs to make .
Name: testuser enable=disagree Purpuse=Complaint Wisdom=test the web
User to be contacted.

Have a nice day!! [/HTML]

Thanks for what help you might have....

e-mail

KevinADC's Avatar
Expert
 
Join Date: Jan 2007
Location: Southern California USA
Posts: 4,091
#2: Feb 15 '07

re: CGI - Accessing form parameters broken


can we see the html form too?
KevinADC's Avatar
Expert
 
Join Date: Jan 2007
Location: Southern California USA
Posts: 4,091
#3: Feb 15 '07

re: CGI - Accessing form parameters broken


We could start with general code clean-up in the mean time:

Expand|Select|Wrap|Line Numbers
  1. #!E:\Perl\bin\perl.exe
  2. use strict;
  3. use warnings;
  4. use diagnostics;
  5. use CGI;
  6. use CGI::Carp qw(warningsToBrowser fatalsToBrowser);
  7. use Net::SMTP;
  8. my $in = CGI->new;
  9. print $in->header(); 
  10. warningsToBrowser(1);
  11. # Get Vars from htm form
  12. my $Contact_me  = $in->param('enable');
  13. my $Employee    = $in->param('name');
  14. my $Purposal    = $in->param('Purpuse');
  15. my $Comments    = $in->param('Wisdom');
  16.  
  17. # message format building phase
  18. my $body = qq~<html><HEAD><TITLE>Post Comment</TITLE></head><body><p>
  19. <font color=blue size=2> Web User wishs to make $Purposal<br>
  20. Name: $Employee <br>
  21. User $Contact_me to be contacted. <br>
  22. <br> <br> $Comments
  23. <br>
  24. <font size=1 color=white> $ENV{REMOTE_ADDR} </font><br>
  25. <H6> Have a nice day!! </H6>
  26. </BODY></html>
  27. ~;   
  28.  
  29. #Test lines begin
  30. print $body;
  31.  
in your code you never printed an http header so the script should not have worked if run as a cgi from a client/server.
Newbie
 
Join Date: Feb 2007
Posts: 3
#4: Feb 17 '07

re: CGI - Accessing form parameters broken


AS you requested, the html code....


[HTML]
<html>
<head>
<title>FEEDBACK</title>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
<style>
#enterName {
visibility: hidden;
padding-left: 50px;
}
</style>
<script type="text/javascript" src="./SDFJASJF;;DSKFSJDFASJSD;KJAF/form.js"></script>
</head>
<body bgcolor="#EEEEEE"> <center>
<table width=80 border=1 cellspacing=0 cellpadding=0><tr><td>
<p><font size="6" color=blue><b><center> Wiser words</b></font><br>
<center> <p><font color=violet size=2><SCRIPT LANGUAGE="JavaScript">var now = new Date();
var days = new Array('Sunday','Monday','Tuesday','Wednesday','Thu rsday','Friday','Saturday');
var months = new Array('January','February','March','April','May',' June','July','August','September','October','Novem ber','December');
var date = ((now.getDate()<10) ? "0" : "")+ now.getDate();
function fourdigits(number) {
return (number < 1000) ? number + 1900 : number;
}
//join
today = days[now.getDay()] + ", " +
months[now.getMonth()] + " " +
date + ", " +
(fourdigits(now.getYear())) ;
document.write(today);</script>
</p>
<hr width="50%" align="center">
<form method="post" enctype="text/plain" action="/cgi/todo.pl" name="enableform" onSubmit="return disableForm(this);">
<table align=center border=0 cellpadding=1 width=30% cellspacing=1>
<td><tr><font size=2 color=green><center>
Do you wish to be contacted? &nbsp; <font size=1.5 color=red>*</font>
<input type="radio" name="enable" value="agree" onclick="agree2();">Yes, I wish to be contacted!
<div id="enterName">Please enter your name: <input type=text id="box" name="name" value=""></div>
<input type="radio" name="enable" value="disagree" onclick="disagree();" checked>No, I wish to be anonyous!
<br><br>

<table align=center border=0 cellpadding=0 width=35% cellspacing=1>
<td><tr><center> Purpose: &nbsp; <font size=1.5 color=red>*</font>
</td></tr></table>
<table align=center border=0 cellpadding=1 width=30% cellspacing=1>
<td><tr><center>
<input type="radio" name="Purpuse" value="Complaint"> Complaint<br>
<input type="radio" name="Purpuse" value="Suggestion" checked> Suggestion
</tr></td></table>
<hr width=50% align="center">
<table align=center border=0 cellpadding=1 width=30% cellspacing=1>
<td><tr><center><p>Comments: &nbsp; <font size=1.5 color=red>* </font>
</tr></td></table>
<textarea name="Wisdom" cols="60" wrap="ON" rows="10"></textarea>
<p><p>
<table width="50%" border="5" cellpadding="10">
<tr>
<td>
<div align="center">
<input type="submit" name="done" value="Send!" onmouseover="goSubmit()" onmouseout="this.value='Send!'">
</div>
</td>
<td>
<div align="center"> <center>
<input type="reset" name="Reset" value="Reset">
</div></tr>
</table>
<font color=red><h6>Fields with an * are required!</h6></font>
</form>
</tr></td></table>
</body>
</html>
[/HTML]


I've also added the perl code to the above perl code.....



#Test lines begin
print "HTTP/1.0 200 OK\n";
print "Content-type: text/html\n\n";
print $body;


I checked a couple of our developer scripts at work and they have these in the code.....

print "HTTP/1.0 200 OK\n";
print "Content-type: text/html\n\n";


Even with them, I still have the variables messed up in the body statement.... Beingthe brain child, I changed the body statments to explude the variables and it still didn't work?


$body = "<html><HEAD><TITLE>Post Mail</TITLE></head><body><p>";
$body .= "<img height\=60 width\=55 src\=\"http\://tuxedo\.capreit\.net/Apps/Documentation/HomeDocumentRepository\.nsf/logo\.JPG\">\n\n";
$body .= "<p><P><font color=blue size=2> Web User wishs to make " . $Purposal \. ."<br>";
$body .= "Name: " . $Employee . '<br>\n";
$body .= " $Con \n";
$body .= " <br> " . $Comments . '<br>\n";
$body .= "<font size=1 color=white>". $ENV{REMOTE_ADDR} \. . " </font><br>\n";
$body .= "<H6> Have a nice day!! </H6> \n";
$body .= "</BODY></html> \n";
Reply