Hi to all. I'm trying to build WebUI with help of CGI::FormBuilder, I managed to make it to process parameters for one "mode", but things turned to bad when I'm trying to add second more "mode", it continues to work with my first "mode", but dies even if I try to build a simple form with only necessary options. Here is some code and it works.
#!/usr/bin/perl -wT use strict; use warnings; use DBI; #use CGI; use CGI qw(:standard); use CGI::FormBuilder; use Data::Dumper; my (@keys,@values,@env_types); my ($keylist,$valuelist,$field,$env_choose); my $o_dbuser = "usr"; my $o_dbpwd = "pwd"; my ($query,$last,$servers_add); my $form = CGI::FormBuilder->new(keepextras => 1); my $mode = $form->cgi_param('mode'); #my $cgi = CGI->new(); #my $mode = $cgi->param('mode'); #my $mode = param('mode'); my $dbh = DBI->connect("DBI:mysql:database=overall;host=192.192.192.19 +2;port=3307", "$o_dbuser", "$o_dbpwd", {'RaiseError' => 1}); my $env_types = "SHOW TABLES FROM `overall` LIKE '%xen_env_%';"; my $sth = $dbh->prepare($env_types); $sth->execute() or die "could not execute", $sth->errstr; while (my $e = $sth->fetchrow_array) { push @env_types, $e; } $sth->finish(); if ($mode eq 'servers') { my $get_summary = "SELECT * FROM `Servers`;"; my $sth0 = $dbh->prepare($get_summary); $sth0->execute(); @keys = @{$sth0->{NAME_lc}} or die "Can't get Field names due +to:$!"; $sth0->finish(); $sth0 = $dbh->prepare($get_summary); $sth0->execute() or die "could not execute", $sth0->errstr; my $dbvalues = $sth0->fetchrow_hashref; $sth0->finish(); $last = $keys[$#keys]; foreach (@keys) { $keylist .= "$_,"; } $keylist =~ s/$last\,/$last/; $servers_add = CGI::FormBuilder->new( fields => [@keys], header => 1, method => 'POST', required => 'ALL', stylesheet => 'fb.css', keepextras => 1, ); $servers_add->field(name => 'env_type', options => [@env_ty +pes], type => 'select',); if ($servers_add->submitted) { $field = $servers_add->field; $last = $keys[$#keys]; for my $k (@keys) { $valuelist .= "'$field->{$k}',"; } $valuelist =~ s/\'\,$/\'/; my $sql = "INSERT INTO `Servers` ($keylist) VALUES($va +luelist);"; $sth0 = $dbh->prepare($sql); $sth0->execute() or die "Could not execute", $sth0->er +rstr; $sth0->finish(); print $servers_add->confirm; } else { print $servers_add->render; } }
So far so good, script dies in case his "mode" parameter is not defined or unknown, and it's correct. Script works as a charm if it used like: http://127.0.1.1/puppeteer/adder.cgi?mode=servers

But if I expanding this chunk of code, like this:

#!/usr/bin/perl -wT use strict; use warnings; use DBI; #use CGI; use CGI qw(:standard); use CGI::FormBuilder; use Data::Dumper; my (@keys,@values,@env_types); my ($keylist,$valuelist,$field,$env_choose); my $o_dbuser = "usr"; my $o_dbpwd = "pwd"; my ($query,$last,$servers_add); my $form = CGI::FormBuilder->new(keepextras => 1); my $mode = $form->cgi_param('mode'); #my $cgi = CGI->new(); #my $mode = $cgi->param('mode'); #my $mode = param('mode'); my $dbh = DBI->connect("DBI:mysql:database=overall;host=192.192.192.19 +2;port=3307", "$o_dbuser", "$o_dbpwd", {'RaiseError' => 1}); my $env_types = "SHOW TABLES FROM `overall` LIKE '%xen_env_%';"; my $sth = $dbh->prepare($env_types); $sth->execute() or die "could not execute", $sth->errstr; while (my $e = $sth->fetchrow_array) { push @env_types, $e; } $sth->finish(); if ($mode eq 'servers') { my $get_summary = "SELECT * FROM `Servers`;"; my $sth0 = $dbh->prepare($get_summary); $sth0->execute(); @keys = @{$sth0->{NAME_lc}} or die "Can't get Field names due +to:$!"; $sth0->finish(); $sth0 = $dbh->prepare($get_summary); $sth0->execute() or die "could not execute", $sth0->errstr; my $dbvalues = $sth0->fetchrow_hashref; $sth0->finish(); $last = $keys[$#keys]; foreach (@keys) { $keylist .= "$_,"; } $keylist =~ s/$last\,/$last/; $servers_add = CGI::FormBuilder->new( fields => [@keys], header => 1, method => 'POST', required => 'ALL', stylesheet => 'fb.css', keepextras => 1, ); $servers_add->field(name => 'env_type', options => [@env_ty +pes], type => 'select',); if ($servers_add->submitted) { $field = $servers_add->field; $last = $keys[$#keys]; for my $k (@keys) { $valuelist .= "'$field->{$k}',"; } $valuelist =~ s/\'\,$/\'/; my $sql = "INSERT INTO `Servers` ($keylist) VALUES($va +luelist);"; $sth0 = $dbh->prepare($sql); $sth0->execute() or die "Could not execute", $sth0->er +rstr; $sth0->finish(); print $servers_add->confirm; } else { print $servers_add->render; } }elsif ($mode eq 'env') { $env_choose = CGI::FormBuilder->new( fields => [qw(env_type env_state)], header => 1, method => 'post', keepextras => 1, ); if ($env_choose->submitted) { print $env_choose->confirm; } }
It just dies with error:

Thu Aug 23 12:29:04 2012] [error] [client 127.0.0.1] Premature end of script headers: adder.cgi

I just can't figure out why it happens and I would appreciate any help, thanks in advance.

In reply to [Resolved]FormBuilder fails in "Multi screen mode" by kazak

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post, it's "PerlMonks-approved HTML":



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.