I have the registration process working so that the custom attribute of "phone" is being stored when the user clicks register, if the user typed a phone number in that is. However, I would like it to be a required field and prevent registration from occurring if left blank. I have not found any keycloak documentation about how to do this.
Asked
Active
Viewed 9,110 times
10
-
Could you show us how you added the custom attribute of 'phone' when the user clicks register. – RAbraham Aug 03 '19 at 16:09
-
@RAbraham : Check here - https://keycloakthemes.com/blog/how-to-add-custom-field-keycloak-registration-page – Anjana Silva Mar 22 '23 at 12:15
1 Answers
3
You have to implement a SPI that extend the registration form. You can use standard FormAction as base. You will have to add you validation logic to validate() method. For instance:
String phoneNumber = formData.getFirst(FIELD_PHONE_NUMBER);
if (Validation.isBlank(phoneNumber) {
errors.add(new FormMessage(FIELD_PHONE_NUMBER, MISSING_PHONE_NUMBER));
}

NathanWindisch
- 65
- 7

Yeray Rodriguez
- 307
- 5
- 14
-
1
-
Would you tell us how to connect keycloak running in a docker container to such an SPI please? It will be useful for someone who is new to keycloak such as me. – Galilo Galilo Nov 05 '22 at 04:04