From d050a637de9caa3bdd6e1e42b22d169446602e9f Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Marc=20V=C3=A9ron?= Date: Thu, 1 Oct 2015 22:00:20 +0200 Subject: [PATCH] Bug 14924 - (follow-up) Add date validation This patch adds a date validation (see comment #3). To test: - Make sure that you test on top of Bug 14936 (Add validation for date strings to Koha::DateUtils - Apply patch - Create a new user or edit an existing user - Try valid dates for date of birth - Try invalid dates as 0000-00-00 or 32/01/1970. You can can copy/paste such strings to the date field, ignore the warning message and submit. Verify that after submit you get a message "Date of birth is invalid" --- members/memberentry.pl | 12 ++++++++++-- 1 file changed, 10 insertions(+), 2 deletions(-) diff --git a/members/memberentry.pl b/members/memberentry.pl index 1a0f83b..7c0cf79 100755 --- a/members/memberentry.pl +++ b/members/memberentry.pl @@ -170,8 +170,12 @@ if ( $op eq 'insert' || $op eq 'modify' || $op eq 'save' || $op eq 'duplicate' ) foreach (qw(dateenrolled dateexpiry dateofbirth)) { next unless exists $newdata{$_}; my $userdate = $newdata{$_} or next; - if ( $userdate ) { + if ( is_formatted_date_string ( $userdate ) || is_formatted_date_string( $userdate, 'iso' ) ) { $newdata{$_} = output_pref({ dt => dt_from_string( $userdate ), dateformat => 'iso', dateonly => 1 }); + } else { + ($userdate eq '0000-00-00') and warn "Data error: $_ is '0000-00-00'"; + $template->param( "ERROR_$_" => 1 ); + push(@errors,"ERROR_$_"); } } # check permission to modify login info. @@ -660,7 +664,11 @@ if (C4::Context->preference('uppercasesurnames')) { foreach (qw(dateenrolled dateexpiry dateofbirth)) { if ( $data{$_} ) { - $data{$_} = output_pref({ dt => dt_from_string( $data{$_} ), dateonly => 1 }); # back to syspref for display + if ( is_formatted_date_string ( $data{$_}, 'iso' ) ) { + $data{$_} = output_pref({ dt => dt_from_string( $data{$_} ), dateonly => 1 }); # back to syspref for display + } else { + $data{$_} = ''; + } } $template->param( $_ => $data{$_}); } -- 1.7.10.4