#!/usr/bin/perl use DBI; use CGI::FormBuilder; $user = $ENV{REMOTE_USER}; # from .htaccess $dbh = DBI->connect(...); # your db here $sth = $dbh->prepare("select * from pers where user = $user"); $defs = $sth->fetchrow_hashref; @fields = qw(first_name last_name email phone address city state zip mail_list); $form = CGI::FormBuilder->new( method => 'post', fields => \@fields, values => $defs, # values from hashref required => 'ALL' ); #### #!/usr/bin/perl -w use strict; use Template; use CGI; use CGI::FormBuilder; use Connect; use CGI::Carp qw(fatalsToBrowser); print "Content-type: text/html\n\n"; my $cgi = new CGI; my $defs ; # hash for default values my $dbh = data_connect(); # link to module that craetes DBI connection #get the default values to load the form my $stmt = "SELECT * FROM imp_lodging WHERE visitor_id = ? AND check_out IS NULL"; my $sth = $dbh->prepare($stmt); $sth->execute($cgi->param('visitor_id')); $defs = $sth->fetchrow_hashref; # for debugging to se if the hash was populated for ( keys %{$defs} ){ print "$_ => $defs->{$_}
"; } my $form = CGI::FormBuilder->new( action => 'edit_visitors.pl', method => 'post', fields => [qw(visitor_id location check_in check_out)], values => $defs, validate => { location => 'INT', check_in => '/^[0-1]\d-[0-3]\d-\d\d\d\d$/', check_out => '/^[0-1]\d-[0-3]\d-\d\d\d\d$/', }, template => { type => 'TT2', template => 'visitor_edit.tt2', variable => 'form', engine => { INCLUDE_PATH => '/inetpub/wwwroot/' . 'lzprotocols.partners.org/' . 'socialservices/src', }, }, );