• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 361
  • Last Modified:

My html Form is not getting parsed to cgi

My html Form is not getting parsed to cgi

My html is not passing the selectbox to the cgi.  If I change the acct in the cgi to a hardcoded value I get a print out value.  Thoughts?



In the html

<select id ="selectBox" name="acct">


In the cgi

$acct  = "$FORM{'acct'}";
print <<EndHTML;
<body>
Account $acct has been disabled now.
</body></html>


When the above line is printed this is printed, Account has been disabled now
0
MatthewF
Asked:
MatthewF
  • 5
  • 3
1 Solution
 
SnarflesCommented:
This is what I wrote in the other question you created with this same text.

"What you need to do is create a javascript function that calls your cgi script... eg

yourdomain.com/cgi-bin/somescript.cgi?acct=blah

Then in your cgi script you need

use CGI qw(:standard);
$acct = new CGI;
my $acct_term = $acct->param('acct');

so $acct_term would then become blah."
0
 
FishMongerCommented:
Javascript is not needed for this issue, but there isn't any harm in using it.

We have not been provided with enough code or info to determine the problem with any certainty, but it sounds like the user isn't selecting any option in the drop down list.  In which case $FORM{'acct'} wouldn't have an assigned value.

You could have one of the options selected as a default.
0
 
MatthewFAuthor Commented:
0
Get 10% Off Your First Squarespace Website

Ready to showcase your work, publish content or promote your business online? With Squarespace’s award-winning templates and 24/7 customer service, getting started is simple. Head to Squarespace.com and use offer code ‘EXPERTS’ to get 10% off your first purchase.

 
FishMongerCommented:
We can't access your script.

Forbidden
You don't have permission to access /incoming/2010/08_w35/340353-disable-account-cgi.pl.txt on this server.
0
 
MatthewFAuthor Commented:
html

<html><head><title>Disable Account</title></head>
<body text=#000000 vLink=#6699ff aLink=#00ff00 link=#6666ff
bgColor=#CCFFFF>
 
<center><h2>Disable Account</h2></center>
 
   
<form method="POST" actiondisable_account.cgi.pl" name="result" onsubmit="return ( validateForm(this)? confirm('Are you sure you want to disable this account?'): false);">
 
 Select an Account to disable <BR><br>
<script type="text/javascript">
function validateForm(f)
{
return true;
}
                  var xmlHttp;
                  var str = "";


var url=location.protocol+'//'+location.host+'/'+'get_accounts.cgi.pl'


function ajaxFunction() {
                       
     
                        try {
             // Firefox, Opera 8.0+, Safari
            xmlHttp=new XMLHttpRequest();
                  } catch (e) {
            // Internet Explorer
                  try {
            xmlHttp=new ActiveXObject("Msxml2.XMLHTTP");
                  } catch (e) {
            try {
            xmlHttp=new ActiveXObject("Microsoft.XMLHTTP");
                  } catch (e) {
            alert("Your browser does not support AJAX!");
                  return false;
                                    }
                                  }
                        }
 
                  var date = new Date();
                  var timestamp = date.getTime();
      xmlHttp.onreadystatechange=postFileReady;
        xmlHttp.open('GET', url + '?time=' + timestamp,true);
                          xmlHttp.send(null);            
                  }
 
                  function postFileReady() {
                  if (xmlHttp.readyState==4) {
                              if (!xmlHttp.status==200) {
                   alert('AJAX error occurred!');
                              return false;      
                              }
            str = xmlHttp.responseText.split("\n");
            var selectBox = document.getElementById('selectBox');
                       
            for (i=0 ; i<str.length ; i++) {
      selectBox.options[i] = new Option(str[i].replace('\r','','g'));
                              }
                           }
                  }
            </script>
       
         <body onload="ajaxFunction();">
      <table>
<select id ="selectBox" name="acct">
</table>      
 
 
</body>
<br><br>
 
      <INPUT type="submit" value="Submit Your Data">
 
 
</<br>
 
 
<br><br>
<a href="javascript:location.href='https://'+window.location.hostname+':444/admin'">Click here to cancel your submission</a><p>

 
</form>
</body></html>



cgi/perl

#!/usr/bin/perl
$ht=`hostname`;
#
$decrypt"XXXXXXXXXXXXXXXXXXXXX"; #### encrypted pwd

$acct  = "_$FORM{'acct'}";



open(OUT,">>/tmp/matt.out");
print OUT "done with account $FORM{'acct'} or $acct\n";
close (OUT);


@doit = `echo "UPDATE Account SET disabled = 1 WHERE name = '$acct';" | /opt/DIFF/filedrive/mysql/bin/mysql -uxxxxx -p$decrypted st`;



print <<EndHTML;
<body>
Account $acct has been disabled now.
</body></html>
EndHTML


print <<EndHTML;
<html><head><title>Thank You</title></head>
<body>

<br><br>

<a href="https://$ht:444/admin/">Return to the Admin Page</a><p>


</body></html>
EndHTML
0
 
FishMongerCommented:
You never declared or assigned anything to the %FORM hash, which is why $acct was empty.
0
 
MatthewFAuthor Commented:
FishMonger,

 I am sure I am missing something, but I have many similar working examples of the html and cgi and in each case in teh perl I declare the form the same way


varaiblename  =  $FORM(declared name in html)
$acct  = "_$FORM{'acct'}";
0
 
FishMongerCommented:
Every Perl script you write should begin with these 2 pragams.

use strict;
use warnings;

The strict pragma will force you to declare all vars, which is done with the 'my' keyword.

You need to use the CGI module to read and parse the form submission.

You should always check the return code of an open call to make sure is was successful and take proper action if it wasn't.

It would be much better to use the DBI module for the db call instead of shelling out via the backticks.
0
 
FishMongerCommented:
The way you have it written, the Perl script doesn't know anything about your form fields.

Here's a quick rewrite of the bulk of your script, which could still use some improvements.

#!/usr/bin/perl

use strict;
use warnings;
use CGI;

my $cgi = CGI->new;
my %FORM = $cgi->Vars;

my $ht=`hostname`;
#
my $decrypt"XXXXXXXXXXXXXXXXXXXXX"; #### encrypted pwd

my $acct  = $FORM{'acct'};



open my $out_fh, '>>', "/tmp/matt.out" or die "failed to open </tmp/matt.out> $!";
print $out_fh "done with account $FORM{'acct'} or $acct\n";
close $out_fh;

Open in new window

0
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

Join & Write a Comment

Featured Post

What Kind of Coding Program is Right for You?

There are many ways to learn to code these days. From coding bootcamps like Flatiron School to online courses to totally free beginner resources. The best way to learn to code depends on many factors, but the most important one is you. See what course is best for you.

  • 5
  • 3
Tackle projects and never again get stuck behind a technical roadblock.
Join Now