SerZKO has asked for the wisdom of the Perl Monks concerning the following question:
Hej Monks,
I have a following code to save my form data to a file :
sub sparaData { open (KOF, ">$konfil") or die "Kan inte \xF6ppna filen $konfil"; flock (KOF, 2) or die "Kan inte l\xE5sa filen $konfil"; $qry-> save (*KOF) or die "Kan inte spara filen $konfil"; close KOF; }
Now, all of my variables that I get from a form are defined withing a subroutine (2nd map) that writes a form which is
sub kundNytt { my @Head = ("Anv. ID", "F\xF6r", "Efter", "Pref", "Bef", "Nytt", "Pr", + "F\xF6r", "Kap"); my $trans = $clrNr; open (TEMP, "<$tempfil") or die "Kan inte \xF6ppna filen $tempfil"; print $qry->start_form(-action => "http://skinnmaskin/cgi-bin/kon.cgi" +); print $qry->table( { Border => 1, Cellpadding => 5, bordercolor =>"#FFFFFF" }, Tr(map { th($_) } @Head), (map { my ($Uid, $Fn, $En, $Pr, $Ank, $Ext, $Or, $Adr) = split /\|/; Tr( td(textfield('UID', $Uid, 6)), td(textfield('FNA', $Fn, 20)), td(textfield('ENA', $En, 35)), td(textfield('PRE', $Pr, 10)), td(textfield('BEF', $Ext, 16)), td(textfield('NYTT', $Ank, 5)), hidden('ADRE', $Addr), td(checkbox_group('GRU',['P', 'F', 'K', 'Ej'],'Ej')), td(checkbox_group('DOL',['Ja', 'Nej'],'Nej')), td(checkbox_group('CMG',['Ja','Nej'],'Nej')), ); } <TEMP>), ); close TEMP; print $qry->hidden('kontor', $trans); print $qry->submit('spara', 'Addera rad'); print $qry->submit('spara', 'Spara'); print $qry->end_form; }
Is it possible make save method executes only if some of variables (e.g. $Ext) are defined (not empty) without exporting variables in "outer space" ?
Thanks in advance.
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re: Print HTML form to file using CGI.pm save method
by Anonymous Monk on Aug 03, 2012 at 19:36 UTC | |
by SerZKO (Beadle) on Aug 03, 2012 at 20:17 UTC | |
by Anonymous Monk on Aug 04, 2012 at 10:20 UTC | |
by SerZKO (Beadle) on Aug 06, 2012 at 07:40 UTC | |
by Anonymous Monk on Aug 03, 2012 at 23:10 UTC | |
by SerZKO (Beadle) on Aug 04, 2012 at 10:05 UTC | |
by Anonymous Monk on Aug 04, 2012 at 10:36 UTC | |
by Anonymous Monk on Aug 04, 2012 at 10:22 UTC |