cyrfan
Forum Replies Created
-
My code is working great so you made a mistake i think (look images please):
https://zupimages.net/up/20/22/jd06.png
https://zupimages.net/up/20/22/my03.pngHi @vvbetai,
Try this:
function um_custom_validate_username( $key, $array, $args ) {
global $regcode;
$regcode = $args[$key];
if ( isset( $regcode ) && $regcode !== ($args[‘user_email’])) {
UM()->form()->add_error( $key, __( ‘Please verify both emails match’, ‘ultimate-member’ ) );
}
}add_action( ‘um_custom_field_validation_confirm_email’, ‘um_custom_validate_username’, 30, 3 );
UPDATE:
This code is really better than i wrote before.
In this example you can get 91 different correct codes (ABC109DEF, ABC110DEF etc etc…):function um_custom_validate_username($key, $array, $args)
{
global $regcode;
$regcode = $args[$key];
$valid_codes = [];
for ($i = 109; $i <= 200; $i++) {
array_push($valid_codes, ‘ABC’ . $i . ‘DEF’);
}
if(isset($regcode) && !in_array($regcode, $valid_codes)) {
UM()->form()->add_error($key, __(‘Code non valide.’, ‘ultimate-member’));
}
}add_action(‘um_custom_field_validation_codecle’, ‘um_custom_validate_username’, 30, 3);
@gabrieldivji your welcome!
hi @gabrieldivji
With $regcode you can add multiple value like in this example with 5 values (You can add more if you want) :function um_custom_validate_username( $key, $array, $args ) {
global $regcode;
$regcode = $args[$key];
if ( isset( $regcode ) && $regcode !==’value1′ && $regcode !==’value2′ && $regcode !==’value3′ && $regcode !==’value4′ && $regcode !==’value5′ ) {
UM()->form()->add_error( $key, __( ‘incorrect value.’, ‘ultimate-member’ ) );
}
}add_action( ‘um_custom_field_validation_T2N_Code’, ‘um_custom_validate_username’, 30, 3 );
- This reply was modified 4 years, 10 months ago by cyrfan.
in this function:
function um_custom_validate_username( $key, $array, $args ) {
// Validate T2N Code
if ( isset( $args[“T2N_Code”] ) && $args[“T2N_Code”] !== ‘TEST_VALUE’ ) {
UM()->form()->add_error( $key, __( ‘Please enter valid code.’, ‘ultimate-member’ ) );
}How can i add severals validate values ?
Regards,
- This reply was modified 4 years, 10 months ago by cyrfan.