Leser: 15
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 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175
#!/usr/bin/perl -w use 5.008; use strict; use diagnostics; use warnings; use CGI; use CGI::Carp qw(fatalsToBrowser warningsToBrowser); use Data::Dumper; $Data::Dumper::Sortkeys = \&dumper_filter; sub dumper_filter { my ($hash) = @_; return [(sort {lc $a cmp lc $b} keys %$hash)]; } $| ++; my $iban_wsdl_getform = 'http://dev.iban-bic.com/Riban/soap2/'; my %account = ( 'acc_user' => 'test', 'acc_pass' => 'test', ); my $cgi = CGI -> new; $cgi -> autoEscape(0); # don't escape & because Data from Server is correct! print $cgi -> header; print $cgi -> start_html ('Test Escape SOAP Content'); print $cgi -> p ('- Begin of script -'); my $modul = 1; eval "use SOAP::Lite; 1;" or $modul = 0; if ($modul) { my $version = SOAP::Lite -> VERSION; print $cgi -> p ("SOAP::Lite $version detected"); my $soap = SOAP::Lite -> new (); # get input mask $soap -> proxy ($iban_wsdl_getform); my ($hash_ref,@params); my %parameter = ( 'country' => 'NL', ); foreach my $key (%parameter) { push @params, \SOAP::Data -> value ( SOAP::Data -> name ('key' => $key) -> type ('xsd:string'), SOAP::Data -> name ('value' => $parameter{$key}) -> type ('xsd:string'), ); } print $cgi -> p ('SENDE:<br><pre>' . Dumper (\@params) . '</pre>'); eval { # do it in eval because smallest errors always cause hard abort in SOAP::Lite # !!ATTENTION!! The SOAP map always must be the first parameter, # username und password always have to be second and third parameter! $hash_ref = $soap -> get_form ( SOAP::Data -> name ('params' => \@params) -> type ('tns:Map'), SOAP::Data -> name ('user' => $account{'acc_user'}) -> type ('xsd:string'), SOAP::Data -> name ('password' => $account{'acc_pass'}) -> type ('xsd:string'), ); }; if (defined $hash_ref) { my $result = $hash_ref -> result; print $cgi -> p ("ERHALTE:<br><pre>" . Dumper (\$result) . "</pre>"); if (lc ($result -> {'done'}) eq 'no') { # prepare next step if ( defined $result -> {'fields'} && ref ($result -> {'fields'}) eq 'ARRAY' && scalar (@{$result -> {'fields'}}) ) { my $error = 0; my $form_fields = ''; for my $i (0 .. scalar (@{$result -> {'fields'}}) - 1) { my $field = build_formfield ($result -> {'fields'} -> [$i]); if ($field ne '') { $form_fields .= $field; } else { $error = $i + 1; last; } } if (!$error) { print $cgi -> start_form (); print $form_fields; print $cgi -> hidden ('acc_user',$account{'acc_user'}); print $cgi -> hidden ('acc_pass',$account{'acc_pass'}); print $cgi -> end_form (); } else { print $cgi -> p ("Sorry, unexpected value(s) in 'field' array # " . ($error - 1) . " in server response IBAN Method get_form!"); print "<pre>" . Dumper (\$result) . "</pre>"; } sub build_formfield { # function to build form field for next step my %deref = %{$_[0]}; my $ref_hidden = $_[1]; my $return = ''; if ( ref (\%deref) eq 'HASH' && defined $deref{'type'} && defined $deref{'id'} && $deref{'id'} ne '' && defined $deref{'value'} && defined $deref{'length'} && defined $deref{'label'} ) { if (lc ($deref{'type'}) eq 'hidden') { $return .= $cgi -> hidden ($deref{'id'},$deref{'value'}); # The following line should be $return .= $cgi -> hidden ('IBAN_KEY',$deref{'id'}); # but CGI module doesn't build it right, takes everytime the wrong value for field # Perhaps a bug? I don't know and do it manually: $return .= '<input type="hidden" name="IBAN_KEY" value="' . $deref{'id'} . '" />'; } elsif (lc ($deref{'type'}) eq 'text') { if ($deref{'label'} ne '') { $return .= '<p>' . $deref{'label'} . ': '; } $return .= $cgi -> textfield ($deref{'id'},$deref{'value'},$deref{'length'},$deref{'length'}); if (defined $deref{'newline'} && $deref{'newline'} eq 'yes') { $return .= '</p>'; } $return .= '<input type="hidden" name="IBAN_KEY" value="' . $deref{'id'} . '" />'; } elsif (lc ($deref{'type'}) eq 'submit') { $return .= $cgi -> submit ('',$deref{'label'}); } elsif (lc ($deref{'type'}) eq 'select') { if ($deref{'label'} ne '') { $return .= '<p>' . $deref{'label'} . ': '; } my %hash_for_popup; my @labels = @{$deref{'options'}}; my @values = @{$deref{'optionids'}}; @hash_for_popup{@values} = @labels; $return .= $cgi -> popup_menu ( -name => $deref{'id'}, -values => $deref{'optionids'}, -labels => \%hash_for_popup, ); if (defined $deref{'newline'} && $deref{'newline'} eq 'yes') { $return .= '</p>'; } } } return $return; } } else { print $cgi -> p ("Sorry, unexpected value(s) of 'fields' in server response IBAN Method get_form!"); print "<pre>" . Dumper (\$result) . "</pre>"; } } } else { print $cgi -> p ( "Sorry, one or more internal errors occurred!" . "<br>Do you perform your request in correct order, first=map, second=user, third=password?" ); } } else { print $cgi -> p ("Sorry, can't find SOAP::Lite!"); } print $cgi -> p ('- End of script -'); print $cgi -> end_html;
Quotehidden() produces a text field that can’t be seen by the user. It is
useful for passing state variable information from one invocation of
the script to the next.
Parameters:
1. The first argument is required and specifies the name of this field
(-name).
2. The second argument is also required and specifies its value
(-default). In the named parameter style of calling, you can
provide a single value here or a reference to a whole list
Fetch the value of a hidden field this way:
$hidden_value = param('hidden_name');
Note, that just like all the other form elements, the value of a hidden
field is "sticky". If you want to replace a hidden field with some
other values after the script has been called once you’ll have to do it
manually:
param('hidden_name','new','values','here');
Quoteyou’ll have to do it manually:
param('hidden_name','new','values','here');
2010-07-29T12:23:35 pqnein, "vorgesehen" ist, dass du den gewünschten wert mit param() einträgst und danach hidden() benutzt.
1 2 3 4 5
$hidden = $cgi->hidden( '-name' => 'name', '-default' => 'value', '-override' => 1 );
2010-07-29T13:26:44 frankesDu kannst bei $cgi->hidden (und andere Tags) auch mit "-override => 1" aufrufen und einen neuen default-Wert zuweisen.