Problem/Motivation
Need to add phone verification validation on registration page, while user creating a account on the site.
if he has already used then we need to show a message to the user "This number is already in use and cannot be assigned to more than one account"
Steps to reproduce
Proposed resolution
add form alter in twilio.module file.
$form['actions']['submit']['#validate'][] = 'twilio_register_validate';
/**
* Custom validation function for phone numbers during registration.
*/
function twilio_register_validate($form, FormStateInterface $form_state) {
$value = $form_state->getValues();
$num_verify = \Drupal::service('twilio.sms')->twilio_verify_number($value['number']);
// Something has been entered but is non numeric.
if (!is_numeric($value['number'])) {
$form_state->setErrorByName('number', t('You must enter a valid phone number'));
return false;
}
if ($num_verify) {
$form_state->setErrorByName('number', t('This number is already in use and cannot be assigned to more than one account'));
return false;
}
return true;
}
Comments
Comment #2
shashank5563 commentedComment #3
rajan kumar commentedAttached patch for restrict user to enter duplicate phone number during user registration.
Comment #5
shashank5563 commentedComment #6
shashank5563 commented@rajan, I have applied your patch.
Thank you for your support.
Comment #7
shashank5563 commented