• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 364
  • 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
Introducing Cloud Class® training courses

Tech changes fast. You can learn faster. That’s why we’re bringing professional training courses to Experts Exchange. With a subscription, you can access all the Cloud Class® courses to expand your education, prep for certifications, and get top-notch instructions.

 
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

Free Tool: Site Down Detector

Helpful to verify reports of your own downtime, or to double check a downed website you are trying to access.

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.

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