my ($class,$r) = @_;
my $errors;
my $this_class_params = { map { $_ => $r->{params}{$_} } $class->columns };
- my $dfv_results;
my $obj;
- if ($class->isa('Class::DBI::DFV')) {
- $obj = eval { My::DBI->create( $this_class_params ) };
- $dfv_results = ($obj) ? undef : $class->dfv_results ;
+ my $dfv_results = Data::FormValidator->check($r->{params}, $class->dfv_profile);
+ if ($dfv_results->success) {
+ $obj = $class->create($this_class_params);
} else {
- $dfv_results = Data::FormValidator->check($r->{params}, $class->dfv_profile);
- if ($dfv_results->success) {
- $obj = $class->create($this_class_params);
- }
- }
-
- # handle dfv errors
- if ( $dfv_results->has_missing ) { # missing fields
- foreach my $field ( $dfv_results->missing ) {
- $errors->{$field} = "$field is required";
+ # handle dfv errors
+ if ( $dfv_results->has_missing ) { # missing fields
+ foreach my $field ( $dfv_results->missing ) {
+ $errors->{$field} = "$field is required";
+ }
}
- }
- if ( $dfv_results->has_invalid ) { # Print the name of invalid fields
- foreach my $field ( $dfv_results->invalid ) {
- $errors->{$field} = "$field is invalid: " . $dfv_results->invalid( $field );
+ if ( $dfv_results->has_invalid ) { # Print the name of invalid fields
+ foreach my $field ( $dfv_results->invalid ) {
+ $errors->{$field} = "$field is invalid: " . $dfv_results->invalid( $field );
+ }
}
}