1 package Webmin::Section;
4 =head2 new Webmin::Section(header, [columns], [title], [width])
5 Create a new form section, which has a header and contains some inputs
9 if (defined(&Webmin::Theme::Section::new) &&
10 caller() !~ /Webmin::Theme::Section/) {
11 return new Webmin::Theme::Section(@_[1..$#_]);
13 my ($self, $header, $columns, $title, $width) = @_;
14 $self = { 'columns' => 4 };
16 $self->set_header($header);
17 $self->set_columns($columns) if (defined($columns));
18 $self->set_title($title) if (defined($title));
19 $self->set_width($width) if (defined($width));
24 Returns the HTML for this form section
30 $rv .= &ui_table_start($self->{'header'},
31 $self->{'width'} ? "width=$self->{'width'}" : undef,
33 foreach my $i (@{$self->{'inputs'}}) {
34 if (is_input($i->[1])) {
36 my @errs = $self->{'form'}->field_errors($i->[1]->get_name());
38 foreach my $e (@errs) {
39 $errs .= "<br><font color=#ff0000>$e</font>\n";
42 $rv .= &ui_table_row($i->[0], $i->[1]->html().$errs,
46 $rv .= &ui_table_row($i->[0],
47 ref($i->[1]) ? $i->[1]->html() : $i->[1], $i->[2]);
50 $rv .= &ui_table_end();
54 =head2 add_input(label, input, [columns])
55 Adds some Webmin::Input object to this form section
59 my ($self, $label, $input, $cols) = @_;
60 push(@{$self->{'inputs'}}, [ $label, $input, $cols ]);
61 $input->set_form($self->{'form'});
64 =head2 add_row(label, text, [columns])
65 Adds a non-editable row to this form section
69 my ($self, $label, $text, $cols) = @_;
70 push(@{$self->{'inputs'}}, [ $label, $text, $cols ]);
73 =head2 add_separator()
74 Adds some kind of separator at this point in the section
79 push(@{$self->{'inputs'}}, [ undef, "<hr>", $self->{'columns'} ]);
84 my ($self, $header) = @_;
85 $self->{'header'} = $header;
90 my ($self, $columns) = @_;
91 $self->{'columns'} = $columns;
96 my ($self, $title) = @_;
97 $self->{'title'} = $title;
100 =head2 set_width([number|number%])
101 Sets the width of this section. Can be called with 100%, 500, or undef to use
102 the minimum possible width.
106 my ($self, $width) = @_;
107 $self->{'width'} = $width;
111 Validates all form inputs, based on the given CGI input hash. Returns a list
112 of errors, each of which is field name, error message and field label.
118 foreach my $i (@{$self->{'inputs'}}) {
119 if (is_input($i->[1])) {
120 foreach my $e ($i->[1]->validate()) {
121 push(@errs, [ $i->[1]->get_name(), $e, $i->[0] ]);
128 =head2 get_value(input-name)
129 Returns the value of the input with the given name.
133 my ($self, $name) = @_;
134 foreach my $i (@{$self->{'inputs'}}) {
135 if (is_input($i->[1]) && $i->[1]->get_name() eq $name) {
136 return $i->[1]->get_value();
142 =head2 set_form(form)
143 Called by the Webmin::Form object when this section is added to it
147 my ($self, $form) = @_;
148 $self->{'form'} = $form;
149 foreach my $i (@{$self->{'inputs'}}) {
150 if (is_input($i->[1])) {
151 $i->[1]->set_form($form);
159 return map { $_->[1] } grep { is_input($_->[1]) } @{$self->{'inputs'}};
162 =head2 is_input(object)
167 return ref($object) && ref($object) =~ /::/ &&
168 $object->isa("Webmin::Input");