M
Marek
Hello all!
Sorry for this long posting. I boiled down my script as far as I
could. But it is still very long!
My Questions:
1. How do I create the $order_date. I am doing something wrong here
2. How do I check, whether the $order_date was changed against the
default: 01/Jan/2009 - 00:00. The $order_date would be later
obligatory (must => 1; it is commented out)
3. How to pass the form elements to the formmail.pl from :
http://nms-cgi.sourceforge.net/ ???
Thank you all for your patience.
marek
#! /usr/bin/perl
use strict;
use warnings;
use CGI qwstandard);
use CGI::Carp qw(fatalsToBrowser);
$CGI:ISABLE_UPLOADS = $CGI:ISABLE_UPLOADS = 1;
$CGI:OST_MAX = $CGI:OST_MAX = 4096;
my $color;
my $order_date;
my $warnung;
my @element_liste = (
{
type => "headline",
name => "Pickup Time",
color => "#C0C0C4"
},
{
type => 'popup',
bez => 'Day/Month/Year/ - hr:min',
# must => 1;
date_time1 => [
{
name => 'day',
value => [
"01", "02", "03", "04", "05", "06", "07", "08",
"09", "10", "11", "12", "13", "14", "15", "16",
"17", "18", "19", "20", "21", "22", "23", "24",
"25", "26", "27", "28", "29", "30", "31"
]
},
{
name => 'month',
value => [
"Jan", "Feb", "Mär", "Apr", "Mai", "Jun",
"Jul", "Aug", "Sep", "Okt", "Nov", "Dez"
]
},
{
name => 'year',
value => [ '2009', '2010', '2011', '2012' ]
}
],
date_time2 => [
{
name => 'hour',
value => [
"01", "02", "03", "04", "05", "06", "07", "08",
"09", "10", "11", "12", "13", "14", "15", "16",
"17", "18", "19", "20", "21", "22", "23", "24"
]
},
{
name => 'minutes',
value => [
"05", "10", "15", "20", "25", "30", "35", "45",
"55", "55"
]
}
]
},
{
type => "headline",
name => "Pickup Place/Destination",
color => "#FFFFFF"
},
{
type => "text",
name => "from_where",
bez => "Von:",
size => 36,
must => 1
},
{
type => "text",
name => "whereto",
bez => "Whereto:",
size => 36,
must => 1
}
);
my $table_start = <<"EOF";
<table width="1006" align="center" border="0" cellspacing="0"
cellpadding="0">
<tr>
<td align="left" valign="middle" bgcolor="#0E1E3F" rowspan="37">
<img src="http://www.munich-taxis.de/pix/grafix/transparent.gif"
alt="" width="3" height="3" />
</td>
<td align="left" valign="middle" bgcolor="#0E1E3F" colspan="2">
<img src="http://www.munich-taxis.de/pix/grafix/transparent.gif"
alt="" width="3" height="3" />
</td>
<td align="left" valign="middle" bgcolor="#0E1E3F" rowspan="37">
<img src="http://www.munich-taxis.de/pix/grafix/transparent.gif"
alt="" width="3" height="3" />
</td>
</tr>
<tr>
<td width="500">
<img src="http://www.munich-taxis.de/grandtaxi/images/
grandtaxi_logo_01.jpg" alt="Logo Grand Taxi" width="500" height="100"/</td>
<td width="500" bgcolor="#FFFFFF">
</td>
</tr>
<tr>
<td bgcolor="#EDD4C3" colspan="2">
<img src="http://www.munich-taxis.de/pix/grafix/transparent.gif"
alt="" width="3" height="3" />
</td>
</tr>
<tr bgcolor="#FFFFFF">
<td valign="middle" colspan="2" align="center">
EOF
my $table_start2 = <<"EOF";
</td>
</tr>
<tr>
<td bgcolor="#EDD4C3" colspan="2">
<img src="http://www.munich-taxis.de/pix/grafix/transparent.gif"
alt="" width="3" height="3" />
</td>
</tr>
EOF
my $table_end = <<"EOF";
<tr>
<td bgcolor="#EDD4C3" colspan="2" height="3">
<img src="http://www.munich-taxis.de/pix/grafix/transparent.gif"
alt="" width="3" height="3" />
</td>
</tr>
<tr>
<td bgcolor="#0E1E3F" colspan="2" height="3">
<img src="http://www.munich-taxis.de/pix/grafix/transparent.gif"
alt="" width="3" height="3" />
</td>
</tr>
</table>
EOF
print header ( -charset => 'utf-8' ),
start_html(
{
-dtd => '-//W3C//DTD XHTML 1.0 Transitional//EN',
-title => 'FormTest',
-style =>
{ 'src' => 'http://www.munich-taxis.de/style/
style_giessl.css' }
}
);
# Dispatch to proper action based on user selection
my $action = lc( param("action") );
if ( $action eq "" ) {
show_form( \@element_liste );
}
elsif ( $action eq "send" ) {
formular_check( \@element_liste );
}
print end_html();
exit(0);
#
----------------------------------------------------------------------
# Eingabe-Formular anzeigen
sub show_form {
my $element_liste_ref = shift;
my @zeilen;
print start_form ( -action => url() );
print $table_start;
if ( defined $order_date ) {
print h1 ("Ihre Bestellung für den $order_date");
}
print p (
{ -class => "vorwort" },
"Bitte geben sie die Registrierungs-Daten ein, und drücken Sie
dann den <strong>Absenden</strong>-Knopf. <br />Felder mit einem
Sternchen* sind Pflichtfelder!"
);
if ( defined $warnung ) {
print p ( { -class => "warnung" }, $warnung )
; # This is the warning, if something is not filled out in
the form ...
}
print $table_start2;
foreach my $f ( @{$element_liste_ref} ) {
my $type = $f->{type};
my $bez = $f->{bez};
$bez .= "*" if $f->{must};
my $class;
if ( $f->{class} ) {
$class = $f->{class};
}
else {
$class = "no_alert";
}
if ( $type eq "headline" ) {
$color = $f->{color};
my $headline = $f->{name};
push(
@zeilen,
Tr(
{ -bgcolor => "$color" },
td( { -colspan => '2' }, h1($headline) )
)
);
}
elsif ( $type eq 'popup' and $f->{bez} =~ /Month/ ) {
my @menus1 = ();
my @menus2 = ();
for ( @{ $f->{date_time1} } ) {
push @menus1,
popup_menu(
-name => $_->{name},
-value => $_->{value}
);
}
for ( @{ $f->{date_time2} } ) {
push @menus2,
popup_menu(
-name => $_->{name},
-value => $_->{value}
);
}
push @zeilen,
Tr(
{ -bgcolor => "$color" },
td( p( { -class => $class }, $bez ) ),
td(
{ -align => 'left' },
join( "/", @menus1 ) . " - " . join( ":",
@menus2 )
)
);
}
if ( $type eq "text" ) {
push(
@zeilen,
Tr(
{ -bgcolor => "$color" },
td( p( { -class => $class }, $bez ) ),
td(
textfield(
-name => $f->{name},
-size => $f->{size}
)
)
)
);
}
}
foreach my $zeile (@zeilen) {
print $zeile;
}
print qq(<tr><td bgcolor="#EDD4C3" colspan="2">);
print p( { -align => 'right' },
defaults( -value => "Alles Löschen" ),
submit( -name => "action", -value => "Send" ) );
print "</td></tr>";
print $table_end;
print endform;
print "<p> </p>";
}
sub formular_check {
my $element_liste_ref = shift;
my @probleme;
foreach my $f ( @{$element_liste_ref} ) {
my $value = param( $f->{name} );
$value = "" unless defined($value);
$value =~ s/^\s+//;
$value =~ s/\s+$//;
$f->{value} = $value;
if ( $f->{bez} =~ /Monat/ ) {
my @dates_day = ();
my @dates_hour = ();
for ( @{ $f->{date_time1} } ) {
my $value = param( $f->{name} );
push( @dates_day, $value ); # but this is not
working!
}
for ( @{ $f->{date_time2} } ) {
my $value = param( $f->{name} );
push( @dates_day, $value ); # but this is not
working!
}
$order_date =
join( '/', @dates_day ) . " - " . join( ':',
@dates_hour );
}
if ( $value eq "" && $f->{must} ) {
my $problem = $f->{bez};
$problem =~ s/:\s*$//;
$problem =~ s/^\s+//;
push( @probleme, $problem );
$f->{class} = 'red_alert'
; # "red_alert" from Stylesheet
}
}
if (@probleme) {
$warnung =
"Es fehlt noch etwas. Bitte füllen Sie die rot markierten Felder
aus: ";
$warnung .= join( ", ", @probleme );
$warnung .= "!";
show_form($element_liste_ref);
# neu anzeigen
return;
}
else {
feedback($element_liste_ref);
# send_order($element_liste_ref);
}
}
sub feedback {
my $element_liste_ref = shift;
print $table_start;
if ( defined $order_date ) {
print h1 ("Your order for $order_date");
}
my @order;
foreach my $f ( @{$element_liste_ref} ) {
my $class = "no_alert";
my $bez = $f->{bez};
my $size = 36;
next if $f->{value} eq "";
my $value = param( $f->{name} );
$value = "" unless defined($value);
$value =~ s/^\s+//;
$value =~ s/\s+$//;
$f->{value} = $value;
push(
@order,
Tr(
{ -bgcolor => "$color" },
td( p( { -class => $class }, $bez ) ),
td(
textfield(
-name => $f->{name},
-size => $size
)
)
)
);
}
print p("Folgende Bestelldaten wurden abgeschickt:");
print $table_start2;
foreach my $best (@order) {
print $best;
}
print qq(<tr><td bgcolor="#EDD4C3" colspan="2">);
print p( { -align => 'right' }, "Rückfahrt bestellen: " );
print "</td></tr>";
print $table_end;
print endform;
print "<p> </p>";
print end_html();
exit(0);
}
# sub send_order {
#
# Formmail.pl # see nms
#
# }
__END__
Sorry for this long posting. I boiled down my script as far as I
could. But it is still very long!
My Questions:
1. How do I create the $order_date. I am doing something wrong here
2. How do I check, whether the $order_date was changed against the
default: 01/Jan/2009 - 00:00. The $order_date would be later
obligatory (must => 1; it is commented out)
3. How to pass the form elements to the formmail.pl from :
http://nms-cgi.sourceforge.net/ ???
Thank you all for your patience.
marek
#! /usr/bin/perl
use strict;
use warnings;
use CGI qwstandard);
use CGI::Carp qw(fatalsToBrowser);
$CGI:ISABLE_UPLOADS = $CGI:ISABLE_UPLOADS = 1;
$CGI:OST_MAX = $CGI:OST_MAX = 4096;
my $color;
my $order_date;
my $warnung;
my @element_liste = (
{
type => "headline",
name => "Pickup Time",
color => "#C0C0C4"
},
{
type => 'popup',
bez => 'Day/Month/Year/ - hr:min',
# must => 1;
date_time1 => [
{
name => 'day',
value => [
"01", "02", "03", "04", "05", "06", "07", "08",
"09", "10", "11", "12", "13", "14", "15", "16",
"17", "18", "19", "20", "21", "22", "23", "24",
"25", "26", "27", "28", "29", "30", "31"
]
},
{
name => 'month',
value => [
"Jan", "Feb", "Mär", "Apr", "Mai", "Jun",
"Jul", "Aug", "Sep", "Okt", "Nov", "Dez"
]
},
{
name => 'year',
value => [ '2009', '2010', '2011', '2012' ]
}
],
date_time2 => [
{
name => 'hour',
value => [
"01", "02", "03", "04", "05", "06", "07", "08",
"09", "10", "11", "12", "13", "14", "15", "16",
"17", "18", "19", "20", "21", "22", "23", "24"
]
},
{
name => 'minutes',
value => [
"05", "10", "15", "20", "25", "30", "35", "45",
"55", "55"
]
}
]
},
{
type => "headline",
name => "Pickup Place/Destination",
color => "#FFFFFF"
},
{
type => "text",
name => "from_where",
bez => "Von:",
size => 36,
must => 1
},
{
type => "text",
name => "whereto",
bez => "Whereto:",
size => 36,
must => 1
}
);
my $table_start = <<"EOF";
<table width="1006" align="center" border="0" cellspacing="0"
cellpadding="0">
<tr>
<td align="left" valign="middle" bgcolor="#0E1E3F" rowspan="37">
<img src="http://www.munich-taxis.de/pix/grafix/transparent.gif"
alt="" width="3" height="3" />
</td>
<td align="left" valign="middle" bgcolor="#0E1E3F" colspan="2">
<img src="http://www.munich-taxis.de/pix/grafix/transparent.gif"
alt="" width="3" height="3" />
</td>
<td align="left" valign="middle" bgcolor="#0E1E3F" rowspan="37">
<img src="http://www.munich-taxis.de/pix/grafix/transparent.gif"
alt="" width="3" height="3" />
</td>
</tr>
<tr>
<td width="500">
<img src="http://www.munich-taxis.de/grandtaxi/images/
grandtaxi_logo_01.jpg" alt="Logo Grand Taxi" width="500" height="100"/</td>
<td width="500" bgcolor="#FFFFFF">
</td>
</tr>
<tr>
<td bgcolor="#EDD4C3" colspan="2">
<img src="http://www.munich-taxis.de/pix/grafix/transparent.gif"
alt="" width="3" height="3" />
</td>
</tr>
<tr bgcolor="#FFFFFF">
<td valign="middle" colspan="2" align="center">
EOF
my $table_start2 = <<"EOF";
</td>
</tr>
<tr>
<td bgcolor="#EDD4C3" colspan="2">
<img src="http://www.munich-taxis.de/pix/grafix/transparent.gif"
alt="" width="3" height="3" />
</td>
</tr>
EOF
my $table_end = <<"EOF";
<tr>
<td bgcolor="#EDD4C3" colspan="2" height="3">
<img src="http://www.munich-taxis.de/pix/grafix/transparent.gif"
alt="" width="3" height="3" />
</td>
</tr>
<tr>
<td bgcolor="#0E1E3F" colspan="2" height="3">
<img src="http://www.munich-taxis.de/pix/grafix/transparent.gif"
alt="" width="3" height="3" />
</td>
</tr>
</table>
EOF
print header ( -charset => 'utf-8' ),
start_html(
{
-dtd => '-//W3C//DTD XHTML 1.0 Transitional//EN',
-title => 'FormTest',
-style =>
{ 'src' => 'http://www.munich-taxis.de/style/
style_giessl.css' }
}
);
# Dispatch to proper action based on user selection
my $action = lc( param("action") );
if ( $action eq "" ) {
show_form( \@element_liste );
}
elsif ( $action eq "send" ) {
formular_check( \@element_liste );
}
print end_html();
exit(0);
#
----------------------------------------------------------------------
# Eingabe-Formular anzeigen
sub show_form {
my $element_liste_ref = shift;
my @zeilen;
print start_form ( -action => url() );
print $table_start;
if ( defined $order_date ) {
print h1 ("Ihre Bestellung für den $order_date");
}
print p (
{ -class => "vorwort" },
"Bitte geben sie die Registrierungs-Daten ein, und drücken Sie
dann den <strong>Absenden</strong>-Knopf. <br />Felder mit einem
Sternchen* sind Pflichtfelder!"
);
if ( defined $warnung ) {
print p ( { -class => "warnung" }, $warnung )
; # This is the warning, if something is not filled out in
the form ...
}
print $table_start2;
foreach my $f ( @{$element_liste_ref} ) {
my $type = $f->{type};
my $bez = $f->{bez};
$bez .= "*" if $f->{must};
my $class;
if ( $f->{class} ) {
$class = $f->{class};
}
else {
$class = "no_alert";
}
if ( $type eq "headline" ) {
$color = $f->{color};
my $headline = $f->{name};
push(
@zeilen,
Tr(
{ -bgcolor => "$color" },
td( { -colspan => '2' }, h1($headline) )
)
);
}
elsif ( $type eq 'popup' and $f->{bez} =~ /Month/ ) {
my @menus1 = ();
my @menus2 = ();
for ( @{ $f->{date_time1} } ) {
push @menus1,
popup_menu(
-name => $_->{name},
-value => $_->{value}
);
}
for ( @{ $f->{date_time2} } ) {
push @menus2,
popup_menu(
-name => $_->{name},
-value => $_->{value}
);
}
push @zeilen,
Tr(
{ -bgcolor => "$color" },
td( p( { -class => $class }, $bez ) ),
td(
{ -align => 'left' },
join( "/", @menus1 ) . " - " . join( ":",
@menus2 )
)
);
}
if ( $type eq "text" ) {
push(
@zeilen,
Tr(
{ -bgcolor => "$color" },
td( p( { -class => $class }, $bez ) ),
td(
textfield(
-name => $f->{name},
-size => $f->{size}
)
)
)
);
}
}
foreach my $zeile (@zeilen) {
print $zeile;
}
print qq(<tr><td bgcolor="#EDD4C3" colspan="2">);
print p( { -align => 'right' },
defaults( -value => "Alles Löschen" ),
submit( -name => "action", -value => "Send" ) );
print "</td></tr>";
print $table_end;
print endform;
print "<p> </p>";
}
sub formular_check {
my $element_liste_ref = shift;
my @probleme;
foreach my $f ( @{$element_liste_ref} ) {
my $value = param( $f->{name} );
$value = "" unless defined($value);
$value =~ s/^\s+//;
$value =~ s/\s+$//;
$f->{value} = $value;
if ( $f->{bez} =~ /Monat/ ) {
my @dates_day = ();
my @dates_hour = ();
for ( @{ $f->{date_time1} } ) {
my $value = param( $f->{name} );
push( @dates_day, $value ); # but this is not
working!
}
for ( @{ $f->{date_time2} } ) {
my $value = param( $f->{name} );
push( @dates_day, $value ); # but this is not
working!
}
$order_date =
join( '/', @dates_day ) . " - " . join( ':',
@dates_hour );
}
if ( $value eq "" && $f->{must} ) {
my $problem = $f->{bez};
$problem =~ s/:\s*$//;
$problem =~ s/^\s+//;
push( @probleme, $problem );
$f->{class} = 'red_alert'
; # "red_alert" from Stylesheet
}
}
if (@probleme) {
$warnung =
"Es fehlt noch etwas. Bitte füllen Sie die rot markierten Felder
aus: ";
$warnung .= join( ", ", @probleme );
$warnung .= "!";
show_form($element_liste_ref);
# neu anzeigen
return;
}
else {
feedback($element_liste_ref);
# send_order($element_liste_ref);
}
}
sub feedback {
my $element_liste_ref = shift;
print $table_start;
if ( defined $order_date ) {
print h1 ("Your order for $order_date");
}
my @order;
foreach my $f ( @{$element_liste_ref} ) {
my $class = "no_alert";
my $bez = $f->{bez};
my $size = 36;
next if $f->{value} eq "";
my $value = param( $f->{name} );
$value = "" unless defined($value);
$value =~ s/^\s+//;
$value =~ s/\s+$//;
$f->{value} = $value;
push(
@order,
Tr(
{ -bgcolor => "$color" },
td( p( { -class => $class }, $bez ) ),
td(
textfield(
-name => $f->{name},
-size => $size
)
)
)
);
}
print p("Folgende Bestelldaten wurden abgeschickt:");
print $table_start2;
foreach my $best (@order) {
print $best;
}
print qq(<tr><td bgcolor="#EDD4C3" colspan="2">);
print p( { -align => 'right' }, "Rückfahrt bestellen: " );
print "</td></tr>";
print $table_end;
print endform;
print "<p> </p>";
print end_html();
exit(0);
}
# sub send_order {
#
# Formmail.pl # see nms
#
# }
__END__