From ffdbbb05f65dd851c92cafd334d5369b07ffe469 Mon Sep 17 00:00:00 2001 From: Emmi Takkinen Date: Wed, 14 Dec 2022 08:36:01 +0200 Subject: [PATCH] Bug 26558: Make guarantor information persist despite an error When one tries to create an account with patron guarantor and error occurs (already used username, wrong age etc.), guarantor information is lost. This patch always saves added patron guarantor information to the template param new_guarantors. To test: 1. Create a new account but cause an error that will keep the account from saving (enter the wrong age for a category or give the patron a username that's already being used). 2. Search for and select a guarantor. 3. Try to save the account and wait for the "The following fields are wrong. Please fix them." message. => Note that the guarantor information is gone and you need to search for and select the guarantor again. 4. Apply this patch. 5. Repeat steps 1.-3. => Note that guarantor information hasn't been lost. This patch also removes code block from duplicate patron check because we now save param new_guarantors even if error doesn't occur. To test: 1. Create a new account but cause a duplicate patron error. 2. Search for and select a guarantor. 3. Try to save the account. => Guarantor information should persist. Sponsored-by: Koha-Suomi Oy --- members/memberentry.pl | 26 +++++++++++++------------- 1 file changed, 13 insertions(+), 13 deletions(-) diff --git a/members/memberentry.pl b/members/memberentry.pl index 64d9aa2aa7..bde77d6ebc 100755 --- a/members/memberentry.pl +++ b/members/memberentry.pl @@ -250,19 +250,6 @@ if ( ( $op eq 'insert' ) and !$nodouble ) { if ( $patrons->count > 0) { $nodouble = 0; $check_member = $patrons->next->borrowernumber; - - - my @new_guarantors; - my @new_guarantor_id = $input->multi_param('new_guarantor_id'); - my @new_guarantor_relationship = $input->multi_param('new_guarantor_relationship'); - foreach my $gid ( @new_guarantor_id ) { - my $patron = Koha::Patrons->find( $gid ); - my $relationship = shift( @new_guarantor_relationship ); - next unless $patron; - my $g = { patron => $patron, relationship => $relationship }; - push( @new_guarantors, $g ); - } - $template->param( new_guarantors => \@new_guarantors ); } } @@ -713,6 +700,19 @@ if ($nok) { $template->param($error) || $template->param( $error => 1); } $template->param(nok => 1); + + #Prevent losing guarantor data if error occurs + my @new_guarantors; + my @new_guarantor_id = $input->multi_param('new_guarantor_id'); + my @new_guarantor_relationship = $input->multi_param('new_guarantor_relationship'); + foreach my $gid ( @new_guarantor_id ) { + my $patron = Koha::Patrons->find( $gid ); + my $relationship = shift( @new_guarantor_relationship ); + next unless $patron; + my $g = { patron => $patron, relationship => $relationship }; + push( @new_guarantors, $g ); + } + $template->param( new_guarantors => \@new_guarantors ); } #Formatting data for display -- 2.34.1