function verify_id_number($id_number, $gender = '', $foreigner = 0) {
$validated = false;
if (is_numeric($id_number) && strlen($id_number) === 13) {
$errors = false;
$num_array = str_split($id_number);
$id_month = $num_array[2] . $num_array[3];
$id_day = $num_array[4] . $num_array[5];
if ($id_month < 1 || $id_month > 12) {
$errors = true;
}
if ($id_day < 1 || $id_day > 31) {
$errors = true;
}
$id_gender = $num_array[6] >= 5 ? 'male' : 'female';
if ($gender && strtolower($gender) !== $id_gender) {
$errors = true;
}
$id_foreigner = $num_array[10];
if (( $foreigner || $id_foreigner ) && (int)$foreigner !== (int)$id_foreigner) {
$errors = true;
}
$even_digits = array();
$odd_digits = array();
foreach ($num_array as $index => $digit) {
if ($index === 0 || $index % 2 === 0) {
$odd_digits[] = $digit;
} else {
$even_digits[] = $digit;
}
}
$check_digit = array_pop($odd_digits);
$added_odds = array_sum($odd_digits);
$concatenated_evens = implode('', $even_digits);
$evensx2 = $concatenated_evens * 2;
$added_evens = array_sum(str_split($evensx2));
$sum = $added_odds + $added_evens;
$last_digit = substr($sum, -1);
$verify_check_digit = (10 - (int)$last_digit) % 10;
if ((int)$verify_check_digit !== (int)$check_digit) {
$errors = true;
}
if (!$errors) {
$validated = true;
}
}
return $validated;
}
add_action('um_submit_form_errors_hook', 'my_custom_validate_id_number', 10, 1);
function my_custom_validate_id_number($post) {
// Assuming 'drivers_id_number' is the key of your field in the form
$id_number = isset($post['drivers_id_number']) ? $post['drivers_id_number'] : '';
// Perform your validation (calling a hypothetical validate_id_number function)
if (!empty($id_number) && !validate_id_number($id_number)) {
UM()->form()->add_error('drivers_id_number', 'Invalid ID Number');
}
}
Please help me to debug this code,
What I need to achieve is to validate the ID number entered in UM form field. If it passes the form should be normally submitted, else display the error
Just wondering if I could get some assistance. I’m following the guide in the documentation on custom validation on fields but I can’t get this to work. I’m trying to implement validation on a password field (not the user_pass field for the user’s account password when registering, rather a second password field.) For example I want the field to only allow 9 digits, no letters and no symbols. Any idea on how to go about this?
Thank you
]]>I would like to replace the error text on the “username” meta key at login, but it does not seem to be fired at all. What I have done so far:
Created a snippet:function um_custom_validate_user_email_details( $key, $array, $args ) {
if ( isset( $args['username'] ) && $args['username'] == '' ) {
UM()->form()->add_error( 'username', __( 'This is a test', 'ultimate-member' ) );
}
}
add_action( 'um_custom_field_validation_user_email_details', 'um_custom_validate_user_email_details', 30, 3 );
In Ultimate Member I went to Forms and updated the Username field in “Default Login” by taking the following steps:
The snippet is activated and all I see is the local Dutch error message which basically says: “Enter your username or email address”. It looks like it’s still getting overwritten somehow.
I hope you can help me.
I created a shortcode. When I submit the form, it shows warnings for empty fields. I fill a field, and It shows warnings on all empty fields in front of it but It doesn’t show for the I created shortcode.
Submitted form: https://gcdnb.pbrd.co/images/rUdOjrfsXkE7.png
Empty inputs in front: https://gcdnb.pbrd.co/images/gvr2qvhlUqI7.png
]]>How can I get placeholders for input fields to work?
Thank you.
Thank you in advance!
]]>Thank you
]]>