Once again: CGI help

Discussion in 'Perl Misc' started by Marek, Oct 6, 2009.

  1. Marek

    Marek Guest

    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 qw:)standard);
    use CGI::Carp qw(fatalsToBrowser);

    $CGI::DISABLE_UPLOADS = $CGI::DISABLE_UPLOADS = 1;
    $CGI::pOST_MAX = $CGI::pOST_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">
    &nbsp;
    </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&uuml;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&ouml;schen" ),
    submit( -name => "action", -value => "Send" ) );
    print "</td></tr>";
    print $table_end;
    print endform;
    print "<p>&nbsp;</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&uuml;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&uuml;ckfahrt bestellen: " );
    print "</td></tr>";
    print $table_end;
    print endform;
    print "<p>&nbsp;</p>";
    print end_html();

    exit(0);
    }

    # sub send_order {
    #
    # Formmail.pl # see nms
    #
    # }

    __END__
    Marek, Oct 6, 2009
    #1
    1. Advertising

  2. Marek

    Jim Gibson Guest

    In article
    <>,
    Marek <> wrote:

    > Hello all!
    >
    > Sorry for this long posting. I boiled down my script as far as I
    > could. But it is still very long!


    It is too long. If you expect to get help with your problem(s), you
    need to write a shorter program that exhibits the problem you are
    having.

    >
    > My Questions:
    >
    > 1. How do I create the $order_date. I am doing something wrong here


    What is $order_date supposed to contain?

    > 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)


    You can compare strings with the eq and ne operators:

    if( $order_date ne $default_date ) {
    # $order_date has been changed
    }

    > 3. How to pass the form elements to the formmail.pl from :
    > http://nms-cgi.sourceforge.net/ ???


    You would define the query string that formmail expects from an
    appropriate web page and call formmail. However, that is probably not
    what you want to do. You would be better off combining your script with
    formmail. If all you want to do is email some information somewhere,
    you don't need all of formmail. Just extract the parts of formmail that
    send email (paying attention to the security measures that formmail
    uses) and add those to your program. Or use one of the many other ways
    to send email from a Perl program.

    >
    > Thank you all for your patience.


    My patience is limited.

    --
    Jim Gibson
    Jim Gibson, Oct 6, 2009
    #2
    1. Advertising

  3. Marek

    Marek Guest


    >
    > My patience is limited.
    >



    So why are you answering? I am beginner, and your answers you gave are
    not really helpful!


    > What is $order_date supposed to contain?


    For that reason I posted the very long (sorry again!) script:

    push( @dates_day, $value ); # but this is not working!


    > You can compare strings with the eq and ne operators:
    >
    > if( $order_date ne $default_date ) {
    > # $order_date has been changed
    > }
    >


    This I know! Even as a beginner.


    > you don't need all of formmail. Just extract the parts of formmail that

    send email

    Not really helpful either. Considering the logic of my script, I have
    no place for <form method="post" action="../cgi-bin/FormMail.pl">. How
    do I hand over the form elements after sub formular_check to
    FormMail.pl ?

    There are people jumping on every excuse, to make them smaller to seem
    themselves bigger.


    marek
    Marek, Oct 7, 2009
    #3
  4. >>>>> "M" == Marek <> writes:

    M> So why are you answering? I am beginner, and your answers you
    M> gave are not really helpful!

    1 - The answers he gave answered your questions clearly and concisely.

    2 - He is also helping you to realize that *everyone's* patience here is
    limited, and that you would do very well to read the Posting Guidelines
    that are posted here frequently and follow them.

    Charlton




    --
    Charlton Wilbur
    Charlton Wilbur, Oct 7, 2009
    #4
    1. Advertising

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Ante Perkovic

    Once again: validating the datagrid

    Ante Perkovic, Jun 25, 2003, in forum: ASP .Net
    Replies:
    0
    Views:
    883
    Ante Perkovic
    Jun 25, 2003
  2. =?Utf-8?B?TWF1cml6aW8gUG9sZXR0bw==?=

    Once logon, the web application returs to login page again

    =?Utf-8?B?TWF1cml6aW8gUG9sZXR0bw==?=, Mar 24, 2006, in forum: ASP .Net
    Replies:
    1
    Views:
    318
    Patrick.O.Ige
    Mar 25, 2006
  3. che
    Replies:
    2
    Views:
    483
  4. Christian Maier
    Replies:
    4
    Views:
    340
    Jens Thoms Toerring
    Feb 18, 2007
  5. Gancy
    Replies:
    4
    Views:
    167
    Rasto Levrinc
    Feb 3, 2005
Loading...

Share This Page