um_submit_form_errors_hook_ not working
-
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 errorThe page I need help with: [log in to see the link]
Viewing 2 replies - 1 through 2 (of 2 total)
Viewing 2 replies - 1 through 2 (of 2 total)
- The topic ‘um_submit_form_errors_hook_ not working’ is closed to new replies.