Skip to content

Commit d182788

Browse files
User: Improve registration form page - refs #7173
1 parent 76623fe commit d182788

File tree

1 file changed

+66
-20
lines changed

1 file changed

+66
-20
lines changed

public/main/auth/registration.php

Lines changed: 66 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -764,36 +764,82 @@ function ($email) {
764764
// EXTRA FIELDS
765765
if (array_key_exists('extra_fields', $allowedFields) || in_array('extra_fields', $allowedFields, true)) {
766766
$extraField = new ExtraField('user');
767+
768+
// Extra fields that must NEVER be shown on the registration form.
769+
// These are internal notification preferences; they belong to the profile settings.
770+
$registrationExtraFieldBlacklist = [
771+
'mail_notify_invitation',
772+
'mail_notify_message',
773+
'mail_notify_group_message',
774+
];
775+
776+
// Build the whitelist of extra fields allowed on registration.
767777
$extraFieldList = [];
768778
if (isset($allowedFields['extra_fields']) && is_array($allowedFields['extra_fields'])) {
769779
$extraFieldList = $allowedFields['extra_fields'];
770780
}
781+
782+
// Ensure condition fields (profile.show_conditions_to_user) are still displayed even if the whitelist is empty.
783+
if (!empty($extraConditions) && is_array($extraConditions)) {
784+
foreach ($extraConditions as $condition) {
785+
if (!empty($condition['variable'])) {
786+
$extraFieldList[] = (string) $condition['variable'];
787+
}
788+
}
789+
}
790+
791+
// Apply blacklist + normalize list.
792+
$extraFieldList = array_values(array_unique(array_filter($extraFieldList, static function ($v) use ($registrationExtraFieldBlacklist) {
793+
$v = (string) $v;
794+
795+
// Remove technical keys and blacklisted fields.
796+
if ($v === '' || in_array($v, $registrationExtraFieldBlacklist, true)) {
797+
return false;
798+
}
799+
800+
return true;
801+
})));
802+
803+
// Required extra fields (if configured) - also apply blacklist to avoid making hidden fields "required".
771804
$settingRequiredFields = api_get_setting('registration.required_extra_fields_in_inscription', true);
772805
$requiredFields = 'false' !== $settingRequiredFields ? $settingRequiredFields : [];
773806

774-
if (!empty($requiredFields) && $requiredFields['options']) {
807+
if (!empty($requiredFields) && isset($requiredFields['options']) && is_array($requiredFields['options'])) {
775808
$requiredFields = $requiredFields['options'];
776809
}
777810

778-
$extraField->addElements(
779-
$form,
780-
0,
781-
[],
782-
false,
783-
false,
784-
$extraFieldList,
785-
[],
786-
[],
787-
false,
788-
false,
789-
[],
790-
[],
791-
false,
792-
[],
793-
$requiredFields,
794-
true
795-
);
796-
$extraFieldsLoaded = true;
811+
if (is_array($requiredFields) && !empty($requiredFields)) {
812+
$requiredFields = array_values(array_filter($requiredFields, static function ($v) use ($registrationExtraFieldBlacklist) {
813+
$v = (string) $v;
814+
return $v !== '' && !in_array($v, $registrationExtraFieldBlacklist, true);
815+
}));
816+
} else {
817+
$requiredFields = [];
818+
}
819+
820+
// Only load extra fields if we have at least one allowed field to show.
821+
// This prevents showing internal fields like mail_notify_* when no whitelist is configured.
822+
if (!empty($extraFieldList)) {
823+
$extraField->addElements(
824+
$form,
825+
0,
826+
[],
827+
false,
828+
false,
829+
$extraFieldList,
830+
[],
831+
[],
832+
false,
833+
false,
834+
[],
835+
[],
836+
false,
837+
[],
838+
$requiredFields,
839+
true
840+
);
841+
$extraFieldsLoaded = true;
842+
}
797843
}
798844

799845
// CAPTCHA

0 commit comments

Comments
 (0)