Solved

My html Form is not getting parsed to cgi

Posted on 2010-08-24
9
350 Views
Last Modified: 2013-12-25
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
Comment
Question by:MatthewF
  • 5
  • 3
9 Comments
 
LVL 9

Expert Comment

by:Snarfles
Comment Utility
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
 
LVL 28

Expert Comment

by:FishMonger
Comment Utility
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
 

Author Comment

by:MatthewF
Comment Utility
0
 
LVL 28

Expert Comment

by:FishMonger
Comment Utility
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
How to improve team productivity

Quip adds documents, spreadsheets, and tasklists to your Slack experience
- Elevate ideas to Quip docs
- Share Quip docs in Slack
- Get notified of changes to your docs
- Available on iOS/Android/Desktop/Web
- Online/Offline

 

Author Comment

by:MatthewF
Comment Utility
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
 
LVL 28

Expert Comment

by:FishMonger
Comment Utility
You never declared or assigned anything to the %FORM hash, which is why $acct was empty.
0
 

Author Comment

by:MatthewF
Comment Utility
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
 
LVL 28

Expert Comment

by:FishMonger
Comment Utility
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
 
LVL 28

Accepted Solution

by:
FishMonger earned 475 total points
Comment Utility
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

Featured Post

IT, Stop Being Called Into Every Meeting

Highfive is so simple that setting up every meeting room takes just minutes and every employee will be able to start or join a call from any room with ease. Never be called into a meeting just to get it started again. This is how video conferencing should work!

Join & Write a Comment

This article describes how to create custom column layout styles for Bootstrap. The article uses 5 columns to illustrate the concept, but the principle can be extended to any number of columns.
Not sure what the best email signature size is? Are you worried about email signature image size? Follow this best practice guide.
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 this fifth video of the Xpdf series, we discuss and demonstrate the PDFdetach utility, which is able to list and, more importantly, extract attachments that are embedded in PDF files. It does this via a command line interface, making it suitable …

728 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

Need Help in Real-Time?

Connect with top rated Experts

11 Experts available now in Live!

Get 1:1 Help Now