Want to win a PS4? Go Premium and enter to win our High-Tech Treats giveaway. Enter to Win

x
?
Solved

My html Form is not getting parsed to cgi

Posted on 2010-08-24
9
Medium Priority
?
358 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
VIDEO: THE CONCERTO CLOUD FOR HEALTHCARE

Modern healthcare requires a modern cloud. View this brief video to understand how the Concerto Cloud for Healthcare can help your organization.

 
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 1900 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

Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

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

This article explains how to prepare an HTML email signature template file containing dynamic placeholders for users' Azure AD data. Furthermore, it explains how to use this file to remotely set up a department-wide email signature policy in Office …
In threads here at EE, each comment has a unique Identifier (ID). It is easy to get the full path for an ID via the right-click context menu. However, we often want to post a short link within a thread rather than the full link. This article shows a…
The viewer will learn how to dynamically set the form action using jQuery.
In a recent question (https://www.experts-exchange.com/questions/29004105/Run-AutoHotkey-script-directly-from-Notepad.html) here at Experts Exchange, a member asked how to run an AutoHotkey script (.AHK) directly from Notepad++ (aka NPP). This video…
Suggested Courses

604 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