Sorry about that...  The code is pasted below.  Again, the probelm is that I
don't get from 'mode0a' to 'mode1'.  If I remove 'mode0' and 'mode0a' and
their associated code from the app. module, things work as expected.

>>>>> Instance script:
#!/usr/local/bin/perl

use strict ;
BEGIN {
  use vars qw(@dirs) ;
  @dirs = qw(/var/slm/work/GenPerl) ;
  use lib @dirs ;
  unshift @INC, @dirs unless $INC[0] eq $dirs[0] ;
}

use TestWebApp1 ;
my $app = TestWebApp1->new() ;
$app->run() ;
<<<<< End instance script

>>>>> App. module
package TestWebApp1 ;
use base 'CGI::Application' ;

use strict;
use DBI;

sub setup {
  my $self = shift;
  my($db, $dbh) ;

  $self->start_mode('mode0');
  $self->run_modes(
                   'mode0' => 'choseDB',
                   'mode0a' => 'loginMessage',
                   'mode1' => 'showform',
                   'mode2' => 'showlist',
                   'mode3' => 'showdetail'
                  );

  # Connect to DBI database
  if ( defined($db = $self->param('db')) ) {
    $dbh = DBI->connect("DBI:mysql:database=$db;host=localhost",
                        'slm',
                        _getSLMMySQLPassword(),
                        {PrintError => 0, # Don't report errors via warn()
                         RaiseError => 1} # Do report errors via die()
                       ) or die "Can't connect to database: $DBI::errstr" ;
    $self->param('mydbh' => $dbh);
  }
}

sub teardown {
  my $self = shift;

  # Disconnect when we're done
  $self->param('mydbh')->disconnect();
}

sub choseDB {
  my $self = shift;
  my $q = $self->query();
  my $dbh = $self->param('mydbh');

  my $html = "" ;
$html .= $q->start_html(-title => "Chose a Database") ;
  $html .= $q->start_form() ;
  $html .= $q->h2("Chose a Database: ") ;
  $html .= $q->popup_menu('db',
                          [ qw(ea ht gp bp76) ],
                          'ea') ;
  $html .= $q->hidden(-name => 'rm', -value => 'mode0a') ;
  $html .= $q->submit(-name => "Select") ;
  $html .= $q->end_form() ;

  $html .= $q->hr() ;
  $html .= "CGI: '$q'  DBH: '$dbh'" ;
  $html .= $q->hr() ;
  $html .= $q->h2("Dump:") ;
  $html .= $self->dump_html() ;
  $html .= $q->hr() ;
  $html .= $q->end_html();

  return $html;
}

sub loginMessage {
  my $self = shift ;
  my $q = $self->query() ;
  my $db = $q->param('mode1') ;

  my $dbh = DBI->connect("DBI:mysql:database=$db;host=localhost",
                         'slm',
                         _getSLMMySQLPassword(),
                         {PrintError => 0, # Don't report errors via warn()
                          RaiseError => 1} # Do report errors via die()
                        ) or die "Can't connect to database: $DBI::errstr" ;
  $self->param('db' => $db) ;
  $self->param('mydbh' => $dbh) ;

  my $html = "" ;
  $html .= $q->start_html(-title => "Message") ;
  $html .= $q->start_form() ;
  if ($dbh) {
    $html .= $q->h2("You are successfully logged into database $db") ;
    $html .= $q->hidden(-name => 'rm', -value => 'mode1') ;
    $html .= $q->submit(-name => "Go") ;
    #$html .= $q->a({href=>"$scriptName?rm=selectAction"},
        #          "You may now start working!") ;
  } else {
    $html .= $q->h2("Unable to connect to database $db") ;
  }
  $html .= $q->end_form() ;

  $html .= $q->hr() ;
  $html .= "CGI: '$q'  DBH: '$dbh'" ;
  $html .= $q->hr() ;
  $html .= $q->h2("Dump:") ;
  $html .= $self->dump_html() ;
  $html .= $q->hr() ;
  $html .= $q->end_html() ;

  return $html ;
}

sub showform {
  my $self = shift;
  my $q = $self->query();
  my $dbh = $self->param('mydbh');

  my $html = "" ;
  $html .= $q->start_html(-title => "GenPerl Select Action") ;
  $html .= $q->start_form() ;
  $html .= $q->h2("Display Objects By Type: ") ;
  $html .= $q->radio_group(-name => 'displayType',
                           -values => [ qw(Subject Kindred Marker) ],
                           -linebreak => 'true') ;
  $html .= $q->hidden(-name => 'rm', -value => 'mode2') ;
  $html .= $q->submit(-name => "Go") ;
  $html .= $q->end_form() ;

  $html .= $q->start_form() ;
  $html .= $q->h2("Display Object By ID: ") ;
  $html .= $q->textfield(-name => 'objID',
                         -size => 12,
                         -maxlength => 24) ;
  $html .= $q->hidden(-name => 'rm', -value => 'mode3') ;
  $html .= $q->submit(-name => "Run Query") ;
  $html .= $q->end_form() ;

  $html .= $q->hr() ;
  $html .= "CGI: '$q'  DBH: '$dbh'" ;
  $html .= $q->hr() ;
  $html .= $q->h2("Dump:") ;
  $html .= $self->dump_html() ;
  $html .= $q->hr() ;
  $html .= $q->end_html();

  return $html;
}

sub showlist {
  my $self = shift;
  my $q = $self->query();
  my $dbh = $self->param('mydbh');
  my $displayType = $q->param("displayType") ;
  my $scriptName = $q->script_name() ;
  my($sth, $arrRef, $id) ;

  my $html = '';
  $html .= $q->start_html(-title => "GenPerl List of $displayType" . "s") ;
  $html .= $q->h1("$displayType:");
  $sth = $dbh->prepare("select name, id from Object
                        where objType = '$displayType'") ;
  $sth->execute() ;
  while ($arrRef = $sth->fetchrow_arrayref()) {
    $id = $arrRef->[1] ;
    $html .= $q->a({href=>"$scriptName?rm=mode3&objID=$id"}, $arrRef->[0]) ;
    $html .= $q->br() ;
  }
  $html .= $q->hr() ;
  $html .= "CGI: '$q'  DBH: '$dbh'" ;
  $html .= $q->hr() ;
  $html .= $q->h2("Dump:") ;
  $html .= $self->dump_html() ;
  $html .= $q->hr() ;
  $html .= $q->end_html();

  return $html;
}

sub showdetail {
  my $self = shift;
  my $dbh = $self->param('mydbh');
  my $q = $self->query();
  my $objID = $q->param("objID");
  my($name, $id, $objType) = $dbh->selectrow_array("select name, id, objType
from Object where id = $objID") ;
  my $html = '';
  $html .= $q->start_html(-title => 'Object $id Detail');
  $html .= "Name: $name" ;
  $html .= $q->br() ;
  $html .= "ID: $id" ;
  $html .= $q->br() ;
  $html .= "Type: $objType" ;
  $html .= $q->br() ;

  $html .= $q->hr() ;
  $html .= "CGI: '$q'  DBH: '$dbh'" ;
  $html .= $q->hr() ;
  $html .= $q->h2("Dump:") ;
  $html .= $self->dump_html() ;
  $html .= $q->hr() ;
  $html .= $q->end_html();

  return $html;
}

sub _getSLMMySQLPassword {
  my($password) ;
  chomp ($password = `cat /usr/local/httpd/cgi-bin/.slm_mysql_passwd`) ;
  return($password) ;
}

1;
<<<<< End app. module

-----Original Message-----
From: Jesse Erlbaum [mailto:[EMAIL PROTECTED]]
Sent: Monday, September 10, 2001 11:37 AM
To: [EMAIL PROTECTED]
Subject: RE: [cgiapp] Problems with the CGI::Application "trick"


Hi Steve --

> The respective scripts and modules that I'm running are
> attached to this
> message.

We didn't get them.  Please post the salient bits of your code in the body
of your message (as opposed to an attachment).


>  test.cgi and TestWebApp.pm work as expected.  When running
> test1.cgi, I never get to run mode 'mode1'.  The 'rm'
> parameter never gets
> set to 'mode1', it is always 'mode0a', so this may be a CGI
> problem and not
> a CGI::Application problem.  However, I thought I'd ask here
> first to see if
> anyone has had similar problems or could give me any clues as
> to what the
> problem is.  TIA.


Without seeing the code, I would hazard a guess (based on this description)
that you are having troubles setting the value of your hidden "mode"
parameter.  The most common mistake is failing to set the "override"
attribute in the hidden() method of CGI.pm.  Many people do this:

   $output .= $q->hidden(-name=>'rm', -value=>'new_mode');

 ...Instead of this:

   $output .= $q->hidden(-name=>'rm', -value=>'new_mode', -override=>1);


Look familiar?  Post your code, if this doesn't fix your problem.


-Jesse-



--

+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
  Jesse Erlbaum ....................... CTO
  [EMAIL PROTECTED] ............. Vanguard Media
  v: 212.242.5317 x115 ...... New York City
+-+-+-+-+-+- http://www.vm.com/ +-+-+-+-+-+-+


---------------------------------------------------------------------
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]


---------------------------------------------------------------------
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]

Reply via email to