4 CXGN::Page::Form::ConfirmStore.pm -- classes to deal with user-modifiable web forms
8 This is a subclass of L<CXGN::Page::Form::Static>, and overrides the functions therein to generate editable components in the form. For more information, see L<CXGN::Page::Form::Static>.
12 Lukas Mueller (lam87@cornell.edu)
18 use CXGN
::Page
::Form
::Static
;
19 use CXGN
::Page
::Form
::Editable
;
21 package CXGN
::Page
::Form
::ConfirmStore
;
23 use base qw
/ CXGN::Page::Form::Editable /;
27 my $self = $class->SUPER::new
(@_);
28 $self->set_static_form(CXGN
::Page
::Form
::Static
->new()) ;
29 $self->set_reset_button_text("Reset");
30 $self->set_submit_button_text("Store");
31 $self->set_submit_method(); #use hardcoded default
37 Whether the form can be filled in.
63 #print STDERR "args hash before in the store function: \n";
64 # while (my ($key, $value) = each(%args)) { print STDERR "$key $value\n"; }
65 #print STDERR "STORING FORM DATA...\n";
67 $self->propagate_input(%args);
71 # commit the changes to the database using the store method on
74 #print STDERR "STORING OBJECT...\n";
76 my %distinct_objects = $self->get_distinct_objects();
79 # check the uniqueness constraints of the object
81 foreach my $k (keys(%distinct_objects)) {
82 my $obj = $distinct_objects{$k};
83 if ($obj->can("exists_in_database")) {
84 my $message = $obj->exists_in_database();
86 my $text = "This object (" . ref($obj) . ") already seems to exist in the database and violates constraints. Please correct your input.";
87 $message = "" unless ($message =~ /[a-zA-Z]/);
88 CXGN
::Page
->new()->message_page($text, $message);
92 foreach my $k (keys %distinct_objects) {
93 #print STDERR " DUMP:" .Data::Dumper::Dumper($distinct_objects{$k});
94 #print STDERR " STORING OBJECT: ".ref($distinct_objects{$k})."\n";
96 my $id = $distinct_objects{$k}->store();
97 $self->set_insert_id($k, $id);
106 Args: a hash with the following keys:
116 required fields: field_name.
126 $self->get_static_form->add_field(%args);
127 my $field = CXGN
::Page
::Form
::Hidden
->new(%args);
128 if(exists $args{validate
})
130 $field->set_validate($args{validate
});
132 if (!exists($self->{fields
})) { $self->{fields
}=(); }
133 push @
{$self->{fields
}}, $field;
138 =head2 function add_textarea
141 Arguments: a hash with the following keys:
151 required fields: field_name.
162 $self->get_static_form->add_textarea(%args);
163 my $field = CXGN
::Page
::Form
::Hidden
->new(%args);
165 if(exists $args{validate
})
167 $field->set_validate($args{validate
});
169 $self->add_field_obj($field);
198 #foreach my $k (keys %args) { print "Args to add_select $k, $args{$k}\n<br />"; }
199 $self->get_static_form->add_select(%args);
200 my $select = CXGN
::Page
::Form
::Hidden
->new(%args);
202 if(exists $args{validate
})
204 $select->set_validate($args{validate
});
206 if (!exists($self->{fields
})) { $self->{fields
}=(); }
207 push @
{$self->{fields
}}, $select;
224 $self->get_static_form->add_hidden(%args);
225 my $hidden = CXGN
::Page
::Form
::EditableHidden
->new(%args);
227 if(exists $args{validate
})
229 $hidden->set_validate($args{validate
});
231 $self->add_field_obj($hidden);
250 $self->get_static_form->add_checkbox(%args);
251 my $checkbox = CXGN
::Page
::Form
::Hidden
->new(%args);
253 $self->add_field_obj($checkbox);
256 =head2 add_radio_list
272 $self->get_static_form->add_radio_list(%args);
273 my $radio = CXGN
::Page
::Form
::Hidden
->new(%args);
275 $self->add_field_obj($radio);
278 =head2 add_multiselect
294 $self->get_static_form->add_multiselect(%args);
295 my $radio = CXGN
::Page
::Form
::Hidden
->new(%args);
297 $self->add_field_obj($radio);
302 return "<form method=\"" . $self->get_submit_method() . "\" action=\"\">"; #must have action parameter for xhtml 1.0+ -- Evan, 1/7/07
307 return "<input type=\"submit\" value=\"" . $self->get_submit_button_text() . "\" />
312 =head2 get_submit_method
318 sub get_submit_method
321 return $self->{form_submit_method
};
324 =head2 set_submit_method
326 'get' or 'post' (case does not matter)
328 default is 'get' if no or invalid argument
332 sub set_submit_method
334 my ($self, $method) = @_;
335 $method = 'get' if(!defined($method) or $method !~ /^get|post$/i);
336 $self->{form_submit_method
} = lc($method); #lowercase
339 sub get_reset_button_text
342 return $self->{reset_button_text
};
345 =head2 set_reset_button_text
347 Args: new button text (default is 'reset form')
349 [1 / 9 / 07] Not currently possible to remove the reset button.
353 sub set_reset_button_text
355 my ($self, $text) = @_;
356 $self->{reset_button_text
} = $text;
359 sub get_submit_button_text
362 return $self->{submit_button_text
};
365 =head2 set_submit_button_text
367 Args: new button text (default is 'store')
371 sub set_submit_button_text
373 my ($self, $text) = @_;
374 $self->{submit_button_text
} = $text;
377 =head2 as_table_string
383 Note: as table does not call validate itself to give some
384 more control on the appearance (you don't wan't the
385 new input field to appear with error messages).
391 sub as_table_string
{
397 my $static= $self->get_static_form();
399 $string .= $static->as_table_string();
401 ### the confirmStore form:
402 my %error_hash = $self->get_error_hash();
403 my %html = $self->get_field_hash();
404 my $has_required_field=0;
406 $string .= $self->get_form_start();
407 $string .= qq { <table
> };
408 foreach my $f ($self->get_fields()) {
410 if (exists($error_hash{$f->get_field_name()})) {
411 $error=$self->get_error_message($error_hash{$f->get_field_name()})."<br />";
414 my $required_field = "";
415 if ($f->get_validate()) {
416 $required_field = qq { <font color
="red">*</font
> };
417 $has_required_field=1;
420 # print everything except the hidden fields
422 if (ref($f)!~/hidden/i) {
423 $string .= "<tr><td>$error".($f->get_display_name())."$required_field</td><td width=\"20\"> </td><td>".($html{$f->get_field_name()})."</td></tr>\n";
428 $string .= qq { <tr
><td colspan
="3" align
="center"> };
430 # print the hidden fields
432 foreach my $f ($self->get_fields()) {
433 if (ref($f)=~/hidden/i) {
434 $string .= $html{$f->get_field_name()};
437 if ($has_required_field) {
438 $string .= qq { (<font color
="red">*</font> denotes required field.)<br /><br
/> };
440 $string .= qq { </td></tr
></table
> };
441 $string .= $self->get_form_end();
443 $string .= $static->get_form_end();
449 =head2 get_static_form
460 sub get_static_form
{
462 return $self->{static_form
};
466 =head2 set_static_form
477 sub set_static_form
{
479 $self->{static_form
}=shift;