Thread CGI-Frage (Abfolge von 3 CGIs in eines packen) (17 answers)
Opened by Kuerbis at 2011-05-15 17:00

Kuerbis
 2011-05-16 08:33
#148659 #148659
User since
2011-03-20
938 Artikel
BenutzerIn
[default_avatar]
Was passt hier noch nicht? Ich komme von `eins` nach `zwei`, aber dann wird immer wieder `zwei` aufgerufen.

Code (perl): (dl )
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
#!/usr/local/bin/perl
use warnings;
use 5.012;
use CGI;
use CGI::Carp qw(fatalsToBrowser warningsToBrowser);
use JSON;

my $ref = [     [ 1, 'eins', '12/11/10', 'sn' ],
                [ 2, 'zwei', '11/12/09', 'cp' ],
                [ 3, 'drei', '04/09/11', 'cp' ], ];
my @radio_values;
for my $el ( @$ref ) {
        push @radio_values, encode_json $el;
}

my $cgi = new CGI();
my $step = $cgi->param('step') // 0;
my @functions = ( \&eins, \&zwei, \&drei );
my $function = $functions[$step] or die "invalid $step";
my $hidden = $cgi->hidden( -name => 'step', -value => $step+1 );
$function->();

sub eins {
        print $cgi->header();
        print $cgi->start_html();
        print $cgi->startform();
        print $cgi->radio_group( -name          => 'choice',
                                 -values        => [ @radio_values ],
                                 -linebreak     => 'true' );
        print $hidden;
        print $cgi->submit( 'OK' );
        print $cgi->endform();       
        print $cgi->end_html();
}

sub zwei {
        my $choice = $cgi->param('choice');
        print $cgi->header();
        print $cgi->start_html();
        print $cgi->startform();
        print $cgi->h2( "Rating: $choice" );
        print $cgi->popup_menu( -name           => 'rating',
                                -values         => [ '+++', '++', '+', '0', '-', '--', '---' ],
                                -default        => '0' );
        print $cgi->br();
        print $cgi->hidden( -name => 'choice', -value => $choice );
        print $hidden;
        print $cgi->submit( 'OK' );
        print $cgi->endform();   
        print $cgi->end_html();
}

sub drei {
        my $choice = $cgi->param('choice');
        my $rating = $cgi->param('rating');
        my $a_ref = decode_json $choice;
        my $name = $a_ref->[1];
        my $table = $a_ref->[-1];
        print $cgi->header();
        print $cgi->start_html();
        print $cgi->p( "Table: $table<br />Name: $name<br />RATING: $rating" );
        print $cgi->end_html();
}

View full thread CGI-Frage (Abfolge von 3 CGIs in eines packen)