Hi. I have been programming for nearly 40 years now, but am new to Perl and FormBuilder. However, I have managed to write a Formbuilder script that reads in a record from a database and updates that record when I hit the submit button. The only problem that I'm having with it is that when I hit the submit button my cgi-bin folder (scripts) is showing twice in my URL. When I correct the URL and hit the enter key, the confirmation screen comes up as it should. Here is my action line when I just run the script using perl from the command line. the script name is "
conn2.pl".
Here is the URL when I submit it to by browser (Google Chrome in this case).
When I look at the source, though, the action line looks like this
And when I hit submit, my URL looks like this
Which of course results in an error 404.
Here is my code (please don't laugh!). :)
#!C:\perl\bin\perl.exe
use strict;
use warnings;
use DBI;
use CGI::FormBuilder;
my @pref_fields;
my @row;
my $defs;
my @ps_signer_opts;
my @mult_out_fles_opts;
my @pallet_min_wgt_opts;
my @auto_nonauto_sort_opts;
my @cont_sort_type_opts;
my @ps8125_mailer_info_opts;
my @auto_start_sentry_opts;
my @move_update_opts;
my @consol_stmt_opts;
my @tray_opts;
my $sqlstmt;
#------------------------------------------
#get Preferences record.
#------------------------------------------
#open connection to Access database
my $dbh = DBI->connect('dbi:ODBC:driver=Microsoft Access Driver (*.mdb);dbq=hypersort.mdb',
"sa" ,"xxxxxxx");
#prepare and execute SQL statement
my $sqlstatement="SELECT * FROM Preferences";
my $pristh = $dbh->prepare($sqlstatement);
$pristh->execute ||
die "Could not execute SQL statement ... maybe invalid?";
my $pref_fields=$pristh->{NUM_OF_FIELDS};
my $ctr=0;
while($ctr < $pref_fields) {
$pref_fields[$ctr] = $pristh->{NAME}[$ctr];
$ctr++;
}
$defs = $pristh->fetchrow_hashref;
#------------------------------------------
#Get options for controls.
#------------------------------------------
&get_ps_signer_opts;
&get_mult_out_files_opts;
&get_pal_min_wgt_opts;
&get_auto_nonauto_sort_opts;
&get_cont_sort_type_opts;
&get_8125_mailer_info_opts;
&get_auto_start_sentry_opts;
&get_move_update_opts;
&get_consol_stmt_opts;
#------------------------------------------
# Init new form.
#------------------------------------------
my $form = CGI::FormBuilder->new(
title => 'HyperSort Preferences',
fields => \@pref_fields,
values => $defs
);
#------------------------------------------
# Assign options to controls.
#------------------------------------------
$form->field(name => 'DefaultStmtSigner', options => \@ps_signer_opts);
$form->field(name => 'DefaultMultipleOutputFiles', options => \@mult_out_fles_opts);
$form->field(name => 'DefaultPalMinWgt', options => \@pallet_min_wgt_opts);
$form->field(name => 'DefaultPieceChoice', options => [qw(I N)]);
$form->field(name => 'DefaultNonAutoSortYN', options => \@auto_nonauto_sort_opts);
$form->field(name => 'DefaultContSortType', options => \@cont_sort_type_opts);
$form->field(name => 'DefaultPS8125MailerInfo', options => \@ps8125_mailer_info_opts);
$form->field(name => 'AutoSentryRun', options => \@auto_start_sentry_opts);
$form->field(name => 'DefaultMoveUpdate', options => \@move_update_opts);
$form->field(name => 'DefaultConsolStmtOption', options => \@consol_stmt_opts);
$form->field(name => 'DefaultWeightUnit', options => [qw(O P)]);
#------------------------------------------
# Check to see if we're submitted and valid
#------------------------------------------
if ($form->submitted && $form->validate) {
#Update database.
$sqlstmt= "UPDATE Preferences SET DefaultOriginZIP = " .
$form->field(name => 'DefaultOriginZIP');
my $pristh = $dbh->prepare($sqlstmt);
$pristh->execute ||
die "Could not execute SQL statement ... maybe invalid?";
$pristh->finish;
$dbh->disconnect();
print $form->confirm(header => 1);
} else {
# Print out the form
print $form->render(header => 1);
}
exit(0);
#------------------------------------------
# Get values for pssigner opts.
#------------------------------------------
sub get_ps_signer_opts
{
#prepare and execute SQL statement
my $sqlstatement=qq/SELECT PSSigner FROM DefaultDropDowns where len(PSSigner) > 0/;
my $sth = $dbh->prepare($sqlstatement);
$sth->execute() ||
die "Could not execute SQL statement ... maybe invalid?";
my $ctr=0;
while($ps_signer_opts[$ctr] = $sth->fetchrow_array) {
$ctr++;
}
pop (@ps_signer_opts);
$sth->finish;
}
#------------------------------------------
# Get values for multiple output files opts.
#------------------------------------------
sub get_mult_out_files_opts
{
#prepare and execute SQL statement
my $sqlstatement=qq/SELECT YN FROM DefaultDropDowns where len(YN) > 0/;
my $sth = $dbh->prepare($sqlstatement);
$sth->execute() ||
die "Could not execute SQL statement ... maybe invalid?";
my $ctr=0;
while($mult_out_fles_opts[$ctr] = $sth->fetchrow_array) {
$ctr++;
}
pop (@mult_out_fles_opts);
$sth->finish;
}
#------------------------------------------
# Get values for pallet min wgt opts.
#------------------------------------------
sub get_pal_min_wgt_opts
{
#prepare and execute SQL statement
my $sqlstatement=qq/SELECT PalletMinWeights FROM DefaultDropDowns where len(PalletMinWeights) > 0/;
my $sth = $dbh->prepare($sqlstatement);
$sth->execute() ||
die "Could not execute SQL statement ... maybe invalid?";
my $ctr=0;
while($pallet_min_wgt_opts[$ctr] = $sth->fetchrow_array) {
$ctr++;
}
pop (@pallet_min_wgt_opts);
$sth->finish;
}
.
.
.
.
.
more subroutines to get options.....
I would appreciate any help that I can get!