« blib/lib/CGI/FormBuilder/Template/CGI_SSI.pm
↑ Summary
blib/lib/CGI/FormBuilder/Messages/base.pm »
| 1 | |||||||||||||||||||||||||||||||||||||||||||
| 2 | ########################################################################### | ||||||||||||||||||||||||||||||||||||||||||
| 3 | # Copyright (c) Nate Wiger http://nateware.com. All Rights Reserved. | ||||||||||||||||||||||||||||||||||||||||||
| 4 | # Please visit http://formbuilder.org for tutorials, support, and examples. | ||||||||||||||||||||||||||||||||||||||||||
| 5 | ########################################################################### | ||||||||||||||||||||||||||||||||||||||||||
| 6 | |||||||||||||||||||||||||||||||||||||||||||
| 7 | # static fields are a special FormBuilder type that turns any | ||||||||||||||||||||||||||||||||||||||||||
| 8 | # normal field into a hidden field with the value printed. | ||||||||||||||||||||||||||||||||||||||||||
| 9 | # As such, the code has to basically handle all field types. | ||||||||||||||||||||||||||||||||||||||||||
| 10 | |||||||||||||||||||||||||||||||||||||||||||
| 11 | package CGI::FormBuilder::Field::static; | ||||||||||||||||||||||||||||||||||||||||||
| 12 | |||||||||||||||||||||||||||||||||||||||||||
| 13 | 2 | ▶ | use strict; | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||
| 14 | 2 | ▶ | use warnings; | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||
| 15 | 2 | ▶ | no warnings 'uninitialized'; | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||
| 16 | |||||||||||||||||||||||||||||||||||||||||||
| 17 | 2 | ▶ | use CGI::FormBuilder::Util; | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||
| 18 | 2 | ▶ | use CGI::FormBuilder::Field; | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||
| 19 | 2 | ▶ | use base 'CGI::FormBuilder::Field'; | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||
| 20 | |||||||||||||||||||||||||||||||||||||||||||
| 21 | |||||||||||||||||||||||||||||||||||||||||||
| 22 | 2 | our $VERSION = '3.10'; | |||||||||||||||||||||||||||||||||||||||||
| 23 | |||||||||||||||||||||||||||||||||||||||||||
| 24 | sub script { | ||||||||||||||||||||||||||||||||||||||||||
| 25 | 26 | ▶ | return ''; # static fields get no messages | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
script: called CC=1 SCAR=0.0
Pod
undocumented
| |||||||||||||||||||||||||||||||||||||||||||
| 26 | } | ||||||||||||||||||||||||||||||||||||||||||
| 27 | |||||||||||||||||||||||||||||||||||||||||||
| 28 | 2 | *render = \&tag; | |||||||||||||||||||||||||||||||||||||||||
| 29 | sub tag { | ||||||||||||||||||||||||||||||||||||||||||
| 30 | 26 | ▶ | local $^W = 0; # -w sucks | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
tag: called CC=11 SCAR=28.6
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||
| 31 | 26 | my $self = shift; | |||||||||||||||||||||||||||||||||||||||||
| 32 | 26 | my $attr = $self->attr; | |||||||||||||||||||||||||||||||||||||||||
| 33 | |||||||||||||||||||||||||||||||||||||||||||
| 34 | 26 | my $jspre = $self->{_form}->jsprefix; | |||||||||||||||||||||||||||||||||||||||||
| 35 | |||||||||||||||||||||||||||||||||||||||||||
| 36 | 26 | my @tag; | |||||||||||||||||||||||||||||||||||||||||
| 37 | 26 | my @value = $self->tag_value; # sticky is different in <tag> | |||||||||||||||||||||||||||||||||||||||||
| 38 | 26 | my @opt = $self->options; | |||||||||||||||||||||||||||||||||||||||||
| 39 | 26 | debug 2, "my(@opt) = \$field->options"; | |||||||||||||||||||||||||||||||||||||||||
| 40 | |||||||||||||||||||||||||||||||||||||||||||
| 41 | # Add in our "Other:" option if applicable | ||||||||||||||||||||||||||||||||||||||||||
| 42 | 26 | ▶ | push @opt, [$self->othername, $self->{_form}{messages}->form_other_default] | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 43 | if $self->other; | ||||||||||||||||||||||||||||||||||||||||||
| 44 | |||||||||||||||||||||||||||||||||||||||||||
| 45 | 26 | debug 2, "$self->{name}: generating $attr->{type} input type"; | |||||||||||||||||||||||||||||||||||||||||
| 46 | |||||||||||||||||||||||||||||||||||||||||||
| 47 | # static fields are actually hidden | ||||||||||||||||||||||||||||||||||||||||||
| 48 | 26 | $attr->{type} = 'hidden'; | |||||||||||||||||||||||||||||||||||||||||
| 49 | |||||||||||||||||||||||||||||||||||||||||||
| 50 | # We iterate over each value - this is the only reliable | ||||||||||||||||||||||||||||||||||||||||||
| 51 | # way to handle multiple form values of the same name | ||||||||||||||||||||||||||||||||||||||||||
| 52 | # (i.e., multiple <input> or <hidden> fields) | ||||||||||||||||||||||||||||||||||||||||||
| 53 | 26 | ▶ | @value = (undef) unless @value; # this creates a single-element array | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 54 | |||||||||||||||||||||||||||||||||||||||||||
| 55 | 26 | for my $value (@value) { | |||||||||||||||||||||||||||||||||||||||||
| 56 | 26 | my $tmp = ''; | |||||||||||||||||||||||||||||||||||||||||
| 57 | |||||||||||||||||||||||||||||||||||||||||||
| 58 | # setup the value | ||||||||||||||||||||||||||||||||||||||||||
| 59 | 26 | $attr->{value} = $value; # override | |||||||||||||||||||||||||||||||||||||||||
| 60 | 26 | ▶ | delete $attr->{value} unless defined $value; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 61 | |||||||||||||||||||||||||||||||||||||||||||
| 62 | # render the tag | ||||||||||||||||||||||||||||||||||||||||||
| 63 | 26 | $tmp .= htmltag('input', $attr); | |||||||||||||||||||||||||||||||||||||||||
| 64 | |||||||||||||||||||||||||||||||||||||||||||
| 65 | # | ||||||||||||||||||||||||||||||||||||||||||
| 66 | # If we have options, lookup the label instead of the true value | ||||||||||||||||||||||||||||||||||||||||||
| 67 | # to print next to the field. This will happen when radio/select | ||||||||||||||||||||||||||||||||||||||||||
| 68 | # lists are converted to 'static'. | ||||||||||||||||||||||||||||||||||||||||||
| 69 | # | ||||||||||||||||||||||||||||||||||||||||||
| 70 | 26 | for (@opt) { | |||||||||||||||||||||||||||||||||||||||||
| 71 | 0 | my($o,$n) = optval($_); | |||||||||||||||||||||||||||||||||||||||||
| 72 | 0 | ▶ | if ($o eq $value) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 73 | 0 | ▶ | $n ||= $attr->{labels}{$o} || ($self->nameopts ? toname($o) : $o); | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition0%0/6
$n ||= $attr->{"labels"}{$o} || ($self->nameopts ? &toname($o) : $o)
$attr->{'labels'}{$o} || ($self->nameopts ? &toname($o) : $o)
MC/DC0%0/3
$n ||= $attr->{"labels"}{$o} || ($self->nameopts ? &toname($o) : $o)
$n
$attr->{'labels'}{$o}
($self->nameopts ? &toname($o) : $o)
Truth table0%0/4
A ||= B || C
A= $nB= $attr->{'labels'}{$o}C= ($self->nameopts ? &toname($o) : $o)
| |||||||||||||||||||||||||||||||||||||||||||
| 74 | 0 | $value = $n; | |||||||||||||||||||||||||||||||||||||||||
| 75 | 0 | last; | |||||||||||||||||||||||||||||||||||||||||
| 76 | } | ||||||||||||||||||||||||||||||||||||||||||
| 77 | } | ||||||||||||||||||||||||||||||||||||||||||
| 78 | |||||||||||||||||||||||||||||||||||||||||||
| 79 | # print the value out too when in a static context | ||||||||||||||||||||||||||||||||||||||||||
| 80 | 26 | ▶ | $tmp .= $self->cleanopts ? escapehtml($value) : $value; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 81 | 26 | push @tag, $tmp; | |||||||||||||||||||||||||||||||||||||||||
| 82 | } | ||||||||||||||||||||||||||||||||||||||||||
| 83 | |||||||||||||||||||||||||||||||||||||||||||
| 84 | 26 | debug 2, "$self->{name}: generated tag = @tag"; | |||||||||||||||||||||||||||||||||||||||||
| 85 | 26 | return join ' ', @tag; # always return scalar tag | |||||||||||||||||||||||||||||||||||||||||
| 86 | } | ||||||||||||||||||||||||||||||||||||||||||
| 87 | |||||||||||||||||||||||||||||||||||||||||||
| 88 | 2 | 1; | |||||||||||||||||||||||||||||||||||||||||
| 89 | |||||||||||||||||||||||||||||||||||||||||||
| 90 | __END__ | ||||||||||||||||||||||||||||||||||||||||||