Solved

My html Form is not getting parsed to cgi

Posted on 2010-08-24
9
355 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
[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
  • 5
  • 3
9 Comments
 
LVL 9

Expert Comment

by:Snarfles
ID: 33510017
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
ID: 33510187
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
What Is Transaction Monitoring and who needs it?

Synthetic Transaction Monitoring that you need for the day to day, which ensures your business website keeps running optimally, and that there is no downtime to impact your customer experience.

 
LVL 28

Expert Comment

by:FishMonger
ID: 33510770
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
 

Author Comment

by:MatthewF
ID: 33511384
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
ID: 33511570
You never declared or assigned anything to the %FORM hash, which is why $acct was empty.
0
 

Author Comment

by:MatthewF
ID: 33511664
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
ID: 33511670
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
ID: 33511745
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

What Is Transaction Monitoring and who needs it?

Synthetic Transaction Monitoring that you need for the day to day, which ensures your business website keeps running optimally, and that there is no downtime to impact your customer experience.

Question has a verified solution.

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

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.
A quick Powershell script I wrote to find old program installations and check versions of a specific file across the network.
The viewer will learn how to look for a specific file type in a local or remote server directory using PHP.
The viewer will learn the benefit of using external CSS files and the relationship between class and ID selectors. Create your external css file by saving it as style.css then set up your style tags: (CODE) Reference the nav tag and set your prop…

724 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