create a form with cgi and a multidimensional array

Discussion in 'Perl Misc' started by Marek, Sep 2, 2009.

  1. Marek

    Marek Guest

    Hello all!


    I have a cgi problem, which I can not resolve alone.

    I have a multidimensional array, to create a form like follows:

    my @element_liste = (
    {
    type => "text",
    name => "firma",
    bez => "Firma:",
    size => 36
    },

    etc.

    my cgi script iterates over this array to create the form:

    foreach my $f ( @{$element_liste_ref} ) {
    my $type = $f->{type};
    my $bez = $f->{bez};
    if ( $type eq "text" ) {
    push(
    @zeile,
    Tr(
    td($bez),
    td(
    textfield(
    -name => $f->{name},
    -size => $f->{size}
    )
    )
    )
    );
    }}

    etc

    Like that every table row is stocked into @zeile for later printing,
    like follows:

    tr
    =================================================================
    td td
    | $bez | <input type="text" name="firma" size="36" /
    > |

    =================================================================

    But now I have the problem, that I need to add a dimension more for
    the date. Explication:

    ,
    {
    type => "popup",
    name => "time",
    bez => "day/month/year/ - hh:mm",
    value => [ "01", "02", "03", etc. ]
    },
    {
    type => "popup",
    name => "time",
    bez => "day/month/year/ - hh:mm",
    value => [ "Jan", "Feb", etc. ],
    },
    {
    type => "popup",
    name => "time",
    bez => "day/month/year/ - hh:mm",
    value => [ "2009", "2010", "2011", "2012" ],
    }

    etc

    And I need the cgi to creat *ONE* table row only with day/month/year -
    hour:min

    tr
    =================================================================
    td td
    | $bez | <select name="time"> |
    | | <option value="01"> |
    | | 01 = days |
    | | etc. |
    | | same for /month/year - hour:min |
    =================================================================


    Could be somebody so kind, to help me with this?



    Best greetings from Munich



    marek
     
    Marek, Sep 2, 2009
    #1
    1. Advertising

  2. Marek

    Guest

    On Wed, 2 Sep 2009 02:00:51 -0700 (PDT), Marek <> wrote:

    >Hello all!
    >
    >
    >I have a cgi problem, which I can not resolve alone.
    >
    >I have a multidimensional array, to create a form like follows:
    >
    >my @element_liste = (
    > {
    > type => "text",
    > name => "firma",
    > bez => "Firma:",
    > size => 36
    > },
    >
    >etc.
    >
    >my cgi script iterates over this array to create the form:
    >
    >foreach my $f ( @{$element_liste_ref} ) {
    > my $type = $f->{type};
    > my $bez = $f->{bez};
    > if ( $type eq "text" ) {
    > push(
    > @zeile,
    > Tr(
    > td($bez),
    > td(
    > textfield(
    > -name => $f->{name},
    > -size => $f->{size}
    > )
    > )
    > )
    > );
    > }}
    >
    >etc
    >
    >Like that every table row is stocked into @zeile for later printing,
    >like follows:
    >
    >tr
    >=================================================================
    >td td
    > | $bez | <input type="text" name="firma" size="36" /
    >> |

    >=================================================================
    >
    >But now I have the problem, that I need to add a dimension more for
    >the date. Explication:
    >
    >,
    > {
    > type => "popup",
    > name => "time",
    > bez => "day/month/year/ - hh:mm",
    > value => [ "01", "02", "03", etc. ]
    > },
    > {
    > type => "popup",
    > name => "time",
    > bez => "day/month/year/ - hh:mm",
    > value => [ "Jan", "Feb", etc. ],
    > },
    > {
    > type => "popup",
    > name => "time",
    > bez => "day/month/year/ - hh:mm",
    > value => [ "2009", "2010", "2011", "2012" ],
    > }
    >
    >etc
    >
    >And I need the cgi to creat *ONE* table row only with day/month/year -
    >hour:min
    >
    >tr
    >=================================================================
    >td td
    > | $bez | <select name="time"> |
    > | | <option value="01"> |
    > | | 01 = days |
    > | | etc. |
    > | | same for /month/year - hour:min |
    >=================================================================
    >
    >
    >Could be somebody so kind, to help me with this?
    >
    >
    >
    >Best greetings from Munich
    >
    >
    >
    >marek


    I know html from the parsing side, so I threw this together.
    You should know what you can get out of html before
    you start using cgi I guess, therefore my trivial solution.

    I looked over cgi.pm the other day, its entirely bizzare.
    The documentation sucks, so I thought I'd look into it.
    Its not clear how you can retrieve information from a form.
    I know -name=> stuff, but is it on a record basis, probably.

    You have to figure that out for yourself.

    The Tr() td() th() shortcuts should work in a nexting fashion,
    but I didn't check cgi.pm and it doesen't say in the perl docs.

    The other thing is I have no idea what you are trying to do.

    Ideally, you want the output, in the case of a record containing
    popups that aren't grouped, to be of this form, which works:

    <TR align=right bgColor=#fffff0>
    <TD colspan="5">cars
    <select name="Foreign">
    <option value="volvo">Volvo</option>
    <option value="saab">Saab</option>
    <option value="mercedes">Mercedes</option>
    <option value="audi">Audi</option>
    </select>
    <select name="Domestic">
    <option value="ford">Ford</option>
    <option value="chevy">Chevy</option>
    <option value="chrysler">Chrysler</option>
    <option value="gm">GM</option>
    </select>
    </TD>

    You should be able to next the popups in one TD,
    giving each a different 'name', assuming you can
    acess 'named' items on a row basis.

    In your case you have a mix of individual popups for each
    of day, month, year AND apparently, a text input for time
    (which was not accounted for in the mix).

    Because your simple definition of types do not cover
    generalization of nesting. For that, you need something more
    sophisticated which I am not spedning time here today because
    I don't believe in the principle utilities of dynamic generation
    that cgi.pm provieds. I would much rather have pre-formed, mild
    editing, ready to pop in the oven type of stuff.

    I have nothing against dynamic generation, but when you build
    the same page over and over again from scratch only to change
    one small thing, it wastes resources. There are better ways.

    Anyway here is my untested solution.
    Ps. Quote only relavent parts if you respond.

    Good luck!
    -sln

    ============================
    my @element_liste = (
    {
    type => 'text',
    name => "firma',
    bez => 'Firma:',
    size => 36
    },
    { },
    { },
    { },
    {
    type => 'popup',
    bez => 'day/month/year/ - hh:mm',
    $puitems => [
    {
    name => 'day',
    value => [ '01', '02', '03', etc. ]
    },
    {
    name => 'month',
    value => [ 'Jan', 'Feb', etc. ],
    },
    {
    name => 'year',
    value => [ '2009', '2010', '2011', '2012' ],
    }
    ]
    }
    );

    foreach my $f ( @{$element_liste_ref} )
    {
    my $type = $f->{type};
    my $bez = $f->{bez};
    if ( $type eq 'text' )
    {
    push @zeile,
    Tr(
    td($bez),
    td( textfield(-name => $f->{name},-size => $f->{size} ))
    );
    }
    elsif ( $type eq 'popup' )
    {
    my @menus;
    for (@$puitems) {
    push @menus,
    popup_menu(
    -name => $_->{name},
    -values => $_->{value}
    );
    }
    push @zeile,
    Tr(
    -align => RIGHT, -bgColor => #fffff0,
    td(
    -colspan => "2",
    $f->{bez},
    @menus
    )
    );
    }
    elsif ( $type eq 'more here' )
    {
    # add more
    }
    }
     
    , Sep 2, 2009
    #2
    1. Advertising

  3. Marek

    Marek Guest

    On 2 Sep., 21:33, wrote:
    > snip



    Hello -sln!



    Thank you very much for your smart suggestion and sorry for my late
    answer! I was trying to adapt your smart suggestion over two days
    now.

    Unfortunately in the @menus there is nothing. I boiled down my script
    to the following. Perhaps I oversaw something?


    Thank you again!


    marek


    #! /usr/bin/perl

    use strict;
    use warnings;
    use CGI qw:)standard escapeHTML);
    use CGI::Carp qw(fatalsToBrowser);

    $CGI::DISABLE_UPLOADS = $CGI::DISABLE_UPLOADS = 1;
    $CGI::pOST_MAX = $CGI::pOST_MAX = 4096;



    my $color;

    my @element_liste = (
    {
    type => "ueberschrift",
    name => "Abholdatum/Abholzeit",
    color => "#C0C0C4"
    },
    {
    type => 'popup',
    bez => 'Tag/Monat/Jahr/ - std:min',
    my $date_time => [
    {
    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' ]
    }
    ]
    }
    );

    print header ( -charset => 'utf-8' ),
    start_html(
    {
    -dtd => '-//W3C//DTD XHTML 1.0 Transitional//EN',
    -title => 'FormTest',
    -style =>
    { 'src' => '../style/style.css' }
    }
    );

    my $table_start = <<"EOF";
    <table width="1006" align="center" border="0" cellspacing="0"
    cellpadding="0">
    <tr>
    <td align="left" valign="middle" bgcolor="#0E1E3F" rowspan="7">
    <img src="../pix/grafix/transparent.gif" alt="" width="3"
    height="3" />
    </td>
    <td align="left" valign="middle" bgcolor="#0E1E3F" colspan="2">
    <img src="../pix/grafix/transparent.gif" alt="" width="3"
    height="3" />
    </td>
    <td align="left" valign="middle" bgcolor="#0E1E3F" rowspan="7">
    <img src="../pix/grafix/transparent.gif" alt="" width="3"
    height="3" />
    </td>
    </tr>
    <tr>
    <td bgcolor="#EDD4C3" colspan="2">
    <img src="../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="../pix/grafix/transparent.gif" alt="" width="3"
    height="3" />
    </td>
    </tr>
    <tr>
    <td bgcolor="#0E1E3F" colspan="2" height="3">
    <img src="../pix/grafix/transparent.gif" alt="" width="3"
    height="3" />
    </td>
    </tr>
    </table>
    EOF



    my $aktion = lc( param("aktion") );
    if ( $aktion eq "" )
    {
    show_form( \@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;

    foreach my $f ( @{$element_liste_ref} ) {
    my $type = $f->{type};
    my $bez = $f->{bez};
    if ( $type eq "ueberschrift" ) {
    $color = $f->{color};
    my $ueberschrift = $f->{name};
    push(
    @zeilen,
    Tr(
    { -bgcolor => "$color" },
    td( { -colspan => '2' }, h1($ueberschrift) )
    )
    );
    }
    elsif ( $type eq 'popup' and $f->{bez} =~ /Monat/ )
    {
    my @menus;
    for (@$date_time) {
    push @menus,
    popup_menu(
    -name => $_->{name},
    -value => $_->{value}
    );
    }
    push @zeilen,
    Tr( { -bgcolor => "$color" }, td( $f->{bez} ), td
    ( @menus ) );
    }
    }

    foreach my $zeile (@zeilen) {
    print $zeile;
    }
    print qq(<tr><td bgcolor="#EDD4C3" colspan="2">);
    print p( { -align => 'right' },
    submit( -name => "aktion", -value => "Absenden" ) );
    print "</td></tr>";
    print $table_end;
    print endform;
    print "<p>&nbsp;</p>";

    }


    __END__
     
    Marek, Sep 4, 2009
    #3
  4. Marek

    Marek Guest

    On 2 Sep., 21:33, wrote:
    > snip



    Hello -sln!



    Thank you very much for your smart suggestion and sorry for my late
    answer! I was trying to adapt your smart suggestion over two days
    now.

    Unfortunately in the @menus there is nothing. I boiled down my script
    to the following. Perhaps I oversaw something?


    Thank you again!


    marek


    #! /usr/bin/perl

    use strict;
    use warnings;
    use CGI qw:)standard escapeHTML);
    use CGI::Carp qw(fatalsToBrowser);

    $CGI::DISABLE_UPLOADS = $CGI::DISABLE_UPLOADS = 1;
    $CGI::pOST_MAX = $CGI::pOST_MAX = 4096;



    my $color;

    my @element_liste = (
    {
    type => "ueberschrift",
    name => "Abholdatum/Abholzeit",
    color => "#C0C0C4"
    },
    {
    type => 'popup',
    bez => 'Tag/Monat/Jahr/ - std:min',
    my $date_time => [
    {
    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' ]
    }
    ]
    }
    );

    print header ( -charset => 'utf-8' ),
    start_html(
    {
    -dtd => '-//W3C//DTD XHTML 1.0 Transitional//EN',
    -title => 'FormTest',
    -style =>
    { 'src' => '../style/style.css' }
    }
    );

    my $table_start = <<"EOF";
    <table width="1006" align="center" border="0" cellspacing="0"
    cellpadding="0">
    <tr>
    <td align="left" valign="middle" bgcolor="#0E1E3F" rowspan="7">
    <img src="../pix/grafix/transparent.gif" alt="" width="3"
    height="3" />
    </td>
    <td align="left" valign="middle" bgcolor="#0E1E3F" colspan="2">
    <img src="../pix/grafix/transparent.gif" alt="" width="3"
    height="3" />
    </td>
    <td align="left" valign="middle" bgcolor="#0E1E3F" rowspan="7">
    <img src="../pix/grafix/transparent.gif" alt="" width="3"
    height="3" />
    </td>
    </tr>
    <tr>
    <td bgcolor="#EDD4C3" colspan="2">
    <img src="../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="../pix/grafix/transparent.gif" alt="" width="3"
    height="3" />
    </td>
    </tr>
    <tr>
    <td bgcolor="#0E1E3F" colspan="2" height="3">
    <img src="../pix/grafix/transparent.gif" alt="" width="3"
    height="3" />
    </td>
    </tr>
    </table>
    EOF



    my $aktion = lc( param("aktion") );
    if ( $aktion eq "" )
    {
    show_form( \@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;

    foreach my $f ( @{$element_liste_ref} ) {
    my $type = $f->{type};
    my $bez = $f->{bez};
    if ( $type eq "ueberschrift" ) {
    $color = $f->{color};
    my $ueberschrift = $f->{name};
    push(
    @zeilen,
    Tr(
    { -bgcolor => "$color" },
    td( { -colspan => '2' }, h1($ueberschrift) )
    )
    );
    }
    elsif ( $type eq 'popup' and $f->{bez} =~ /Monat/ )
    {
    my @menus;
    for (@$date_time) {
    push @menus,
    popup_menu(
    -name => $_->{name},
    -value => $_->{value}
    );
    }
    push @zeilen,
    Tr( { -bgcolor => "$color" }, td( $f->{bez} ), td
    ( @menus ) );
    }
    }

    foreach my $zeile (@zeilen) {
    print $zeile;
    }
    print qq(<tr><td bgcolor="#EDD4C3" colspan="2">);
    print p( { -align => 'right' },
    submit( -name => "aktion", -value => "Absenden" ) );
    print "</td></tr>";
    print $table_end;
    print endform;
    print "<p>&nbsp;</p>";

    }


    __END__
     
    Marek, Sep 4, 2009
    #4
  5. Marek

    Guest

    Re: create a form with cgi and a multidimensional array (0/1)

    On Fri, 4 Sep 2009 00:39:25 -0700 (PDT), Marek <> wrote:

    >On 2 Sep., 21:33, wrote:
    >> snip

    >
    >
    >Hello -sln!
    >
    >
    >
    >Thank you very much for your smart suggestion and sorry for my late
    >answer! I was trying to adapt your smart suggestion over two days
    >now.
    >
    >Unfortunately in the @menus there is nothing. I boiled down my script
    >to the following. Perhaps I oversaw something?
    >


    My fault, I rushed it. It is fixed below, and it runs on my
    machine. You may need to cleanup the output format
    of indentation on the cgi generated stuff.

    Thanks, it was fun and I learned some details on page generation.
    Maybe I will put some more time into it.
    Let me know how it works out.

    -sln
    ========================
    use strict;
    use warnings;
    use CGI qw:)standard escapeHTML);
    use CGI::Carp qw(fatalsToBrowser);

    $CGI::DISABLE_UPLOADS = $CGI::DISABLE_UPLOADS = 1;
    $CGI::pOST_MAX = $CGI::pOST_MAX = 4096;



    my $color;

    my @element_liste = (
    {
    type => "ueberschrift",
    name => "Abholdatum/Abholzeit",
    color => "#C0C0C4"
    },
    {
    type => 'popup',
    bez => 'Tag/Monat/Jahr/ - std:min',
    date_time => [
    {
    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' ]
    }
    ]
    }
    );

    print header ( -charset => 'utf-8' ),
    start_html(
    {
    -dtd => '-//W3C//DTD XHTML 1.0 Transitional//EN',
    -title => 'FormTest',
    -style =>
    { 'src' => '../style/style.css' }
    }
    );

    my $table_start = <<"EOF";
    <table width="1006" align="center" border="0" cellspacing="0" cellpadding="0">
    <tr>
    <td align="left" valign="middle" bgcolor="#0E1E3F" rowspan="7">
    <img src="../pix/grafix/transparent.gif" alt="" width="3" height="3" />
    </td>
    <td align="left" valign="middle" bgcolor="#0E1E3F" colspan="2">
    <img src="../pix/grafix/transparent.gif" alt="" width="3" height="3" />
    </td>
    <td align="left" valign="middle" bgcolor="#0E1E3F" rowspan="7">
    <img src="../pix/grafix/transparent.gif" alt="" width="3" height="3" />
    </td>
    </tr>
    <tr>
    <td bgcolor="#EDD4C3" colspan="2">
    <img src="../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="../pix/grafix/transparent.gif" alt="" width="3" height="3" />
    </td>
    </tr>
    <tr>
    <td bgcolor="#0E1E3F" colspan="2" height="3">
    <img src="../pix/grafix/transparent.gif" alt="" width="3" height="3" />
    </td>
    </tr>
    </table>
    EOF



    my $aktion = lc( param("aktion") );
    if ( $aktion eq "" )
    {
    show_form( \@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;

    foreach my $f ( @{$element_liste_ref} ) {
    my $type = $f->{type};
    my $bez = $f->{bez};
    if ( $type eq "ueberschrift" )
    {
    $color = $f->{color};
    my $ueberschrift = $f->{name};
    push @zeilen,
    Tr(
    { -bgcolor => "$color" },
    td( { -colspan => '2' }, h1($ueberschrift) )
    );
    }
    elsif ( $type eq 'popup' and $f->{bez} =~ /Monat/ )
    {
    my @menus = ();
    for (@{$f->{date_time}}) {
    push @menus,
    popup_menu(
    -name => $_->{name},
    -value => $_->{value}
    );
    }
    push @zeilen,
    Tr(
    { -bgcolor => "$color" },
    td( {-align => 'center' }, $f->{bez} ),
    td( {-align => 'left' }, @menus )
    );
    # or, any of these works just fine ...
    #
    # Tr(
    # { -bgcolor => "$color", -align => 'center' },
    # td( { -colspan => '2' }, $f->{bez}, @menus ) # <- this uses one td()
    # );
    #
    # Tr(
    # { -bgcolor => "$color" },
    # td( $f->{bez} ), td( @menus )
    # );
    }
    }

    foreach my $zeile (@zeilen) {
    print $zeile;
    }
    print qq(<tr><td bgcolor="#EDD4C3" colspan="2">);
    print p( { -align => 'right' },
    submit( -name => "aktion", -value => "Absenden" ) );
    print "</td></tr>";
    print $table_end;
    print endform;
    print "<p>&nbsp;</p>";

    }
    __END__
     
    , Sep 4, 2009
    #5
  6. Marek

    Marek Guest

    Re: create a form with cgi and a multidimensional array (0/1)

    On 4 Sep., 12:01, wrote:
    > snip



    Wow! -sln I am very grateful for your help! I learned a lot! Here just
    for fun, my adaptation a bit more complicate ...


    Best greetings from Munich


    marek


    #! /usr/bin/perl

    use strict;
    use warnings;
    use CGI qw:)standard escapeHTML);
    use CGI::Carp qw(fatalsToBrowser);

    $CGI::DISABLE_UPLOADS = $CGI::DISABLE_UPLOADS = 1;
    $CGI::pOST_MAX = $CGI::pOST_MAX = 4096;

    my $color;

    my @element_liste = (
    {
    type => "ueberschrift",
    name => "Abholdatum/Abholzeit",
    color => "#C0C0C4"
    },
    {
    type => 'popup',
    bez => 'Tag/Monat/Jahr/ - std:min',
    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"
    ]
    }
    ]
    }
    );


    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' }
    }
    );

    my $table_start = <<"EOF";
    <table width="1006" align="center" border="0" cellspacing="0"
    cellpadding="0">
    <tr>
    <td align="left" valign="middle" bgcolor="#0E1E3F" rowspan="7">
    <img src="../pix/grafix/transparent.gif" alt="" width="3"
    height="3" />
    </td>
    <td align="left" valign="middle" bgcolor="#0E1E3F" colspan="2">
    <img src="../pix/grafix/transparent.gif" alt="" width="3"
    height="3" />
    </td>
    <td align="left" valign="middle" bgcolor="#0E1E3F" rowspan="7">
    <img src="../pix/grafix/transparent.gif" alt="" width="3"
    height="3" />
    </td>
    </tr>
    <tr>
    <td bgcolor="#EDD4C3" colspan="2">
    <img src="../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="../pix/grafix/transparent.gif" alt="" width="3"
    height="3" />
    </td>
    </tr>
    <tr>
    <td bgcolor="#0E1E3F" colspan="2" height="3">
    <img src="../pix/grafix/transparent.gif" alt="" width="3"
    height="3" />
    </td>
    </tr>
    </table>
    EOF

    # Dispatch to proper action based on user selection

    my $aktion = lc( param("aktion") ); # aktion: beim Auslesen
    kleinschreiben
    if ( $aktion eq "" ) # erster Aufruf der Skripts
    {
    show_form( \@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;

    foreach my $f ( @{$element_liste_ref} ) {
    my $type = $f->{type};
    my $bez = $f->{bez};
    if ( $type eq "ueberschrift" ) {
    $color = $f->{color};
    my $ueberschrift = $f->{name};
    push(
    @zeilen,
    Tr(
    { -bgcolor => "$color" },
    td( { -colspan => '2' }, h1($ueberschrift) )
    )
    );
    }
    elsif ( $type eq 'popup' and $f->{bez} =~ /Monat/ ) {
    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( { -align => 'center' }, $f->{bez} ),
    td( { -align => 'left' }, join( "/", @menus1 ) . " -
    " . join( ":", @menus2 ) )
    );
    }
    }

    foreach my $zeile (@zeilen) {
    print $zeile;
    }
    print qq(<tr><td bgcolor="#EDD4C3" colspan="2">);
    print p( { -align => 'right' },
    submit( -name => "aktion", -value => "Absenden" ) );
    print "</td></tr>";
    print $table_end;
    print endform;
    print "<p>&nbsp;</p>";

    }

    __END__
     
    Marek, Sep 4, 2009
    #6
  7. Marek

    Guest

    Re: create a form with cgi and a multidimensional array (0/1)

    On Fri, 4 Sep 2009 07:22:57 -0700 (PDT), Marek <> wrote:

    >On 4 Sep., 12:01, wrote:

    <snip>
    >Here just
    >for fun, my adaptation a bit more complicate ...
    >
    >
    >Best greetings from Munich
    >
    >
    >marek
    >
    >


    I like it, works great! Background colors look very nice.
    See, you added time menu's.

    > td( { -align => 'left' }, join( "/", @menus1 ) . " - " . join( ":", @menus2 ) )

    ^ ^
    Its nice you can do join here but its not necessary
    and actually slows it down. As you see td() takes multiple parameters
    in a list. If a list item is a anonymous hash, its an attribute, otherwise
    the element is already joined inside the td() sub.
    So, it can be replaced by this without creating the larger temporary.

    td( { -align => 'left' }, join( "/", @menus1 ), ' - ', join( ":", @menus2 ) )

    I thought you were going with input fields for hours:minutes, but this works good.

    See ya.
    -sln
     
    , Sep 5, 2009
    #7
    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. Replies:
    1
    Views:
    856
    Rob Williscroft
    Jun 28, 2004
  2. Replies:
    2
    Views:
    427
    Srini
    Aug 18, 2005
  3. nitinm
    Replies:
    2
    Views:
    349
    Barry Schwarz
    Sep 14, 2007
  4. Stefan Fischer
    Replies:
    2
    Views:
    358
    Stefan Fischer
    Feb 23, 2010
  5. Keiron Waites
    Replies:
    5
    Views:
    132
    Kent Feiler
    Oct 22, 2003
Loading...

Share This Page