diff --git a/koha-tmpl/opac-tmpl/bootstrap/en/modules/opac-memberentry.tt b/koha-tmpl/opac-tmpl/bootstrap/en/modules/opac-memberentry.tt
index b28d6c98ea..7acd45af30 100644
--- a/koha-tmpl/opac-tmpl/bootstrap/en/modules/opac-memberentry.tt
+++ b/koha-tmpl/opac-tmpl/bootstrap/en/modules/opac-memberentry.tt
@@ -907,7 +907,11 @@
[% IF loop.first %][% END %]
[% form_id = 'patron-attr-' _ Math.int( Math.rand(1000000) ) %]
-
+ [% IF pa.type.mandatory && pa.type.opac_editable %]
+
+ [% ELSE %]
+
+ [% END %]
[% IF pa.type.opac_editable %]
[% IF ( pa.type.authorised_value_category ) %]
@@ -928,6 +932,9 @@
[% ELSE %]
[% END %]
+ [% IF pa.type.mandatory %]
+ Required
+ [% END %]
Clear
[% IF ( pa.type.repeatable ) %]
New
diff --git a/opac/opac-memberentry.pl b/opac/opac-memberentry.pl
index 3825403029..a076cd31b0 100755
--- a/opac/opac-memberentry.pl
+++ b/opac/opac-memberentry.pl
@@ -123,7 +123,7 @@ if ( $action eq 'create' ) {
%borrower = DelEmptyFields(%borrower);
- my @empty_mandatory_fields = CheckMandatoryFields( \%borrower, $action );
+ my @empty_mandatory_fields = (CheckMandatoryFields( \%borrower, $action ), CheckMandatoryAttributes( \%borrower, $attributes ) );
my $invalidformfields = CheckForInvalidFields(\%borrower);
delete $borrower{'password2'};
my $cardnumber_error_code;
@@ -259,7 +259,7 @@ elsif ( $action eq 'update' ) {
$borrower{borrowernumber} = $borrowernumber;
my @empty_mandatory_fields =
- CheckMandatoryFields( \%borrower, $action );
+ ( CheckMandatoryFields( \%borrower, $action ), CheckMandatoryAttributes( \%borrower, $attributes ) );
my $invalidformfields = CheckForInvalidFields(\%borrower);
# Send back the data to the template
@@ -412,6 +412,20 @@ sub CheckMandatoryFields {
return @empty_mandatory_fields;
}
+sub CheckMandatoryAttributes{
+ my ( $borrower, $attributes ) = @_;
+
+ my @empty_mandatory_fields;
+
+ for my $attribute (@$attributes ) {
+ my $attr = Koha::Patron::Attribute::Types->find($attribute->{code});
+ push @empty_mandatory_fields, $attribute->{code}
+ if $attr && $attr->mandatory && $attribute->{attribute} =~ m|^\s*$|;
+ }
+
+ return @empty_mandatory_fields;
+}
+
sub CheckForInvalidFields {
my $borrower = shift;
my @invalidFields;
@@ -691,7 +705,8 @@ sub ParsePatronAttributes {
}
foreach my $code ( keys %{$delete_candidates} ) {
- if ( Koha::Patron::Attributes->search({
+ if ( not $borrowernumber # self-registration
+ || Koha::Patron::Attributes->search({
borrowernumber => $borrowernumber, code => $code })->count > 0 )
{
push @attributes, { code => $code, attribute => '' }