Support for Drupal 7 is ending on 5 January 2025—it’s time to migrate to Drupal 10! Learn about the many benefits of Drupal 10 and find migration tools in our resource center.
sms_send_form_validate()
checks if the number passes validation using sms_formatter()
:
function sms_send_form_validate($form, &$form_state) {
if (!sms_formatter($form_state['values']['number'])) {
form_set_error('number', t('You must enter a valid phone number.'));
}
}
Curiously, sms_validate_number()
does not perform this check:
if (!strlen($number)) {
return t('The phone number is invalid.');
}
// Allow the active gateway to provide number validation
$gateway = sms_default_gateway();
if (function_exists($gateway['validate number']) && $error = $gateway['validate number']($number, $options)) {
return $error;
}
I propose it should, as that would make a lot of sense:
if (!strlen($number) || sms_formatter($number) === FALSE) {
return t('The phone number is invalid.');
}
// Allow the active gateway to provide number validation
$gateway = sms_default_gateway();
if (function_exists($gateway['validate number']) && $error = $gateway['validate number']($number, $options)) {
return $error;
}
Comments
Comment #1
jpmckinney CreditAttribution: jpmckinney commentedComment #2
univate CreditAttribution: univate commentedThe sms_formatter function is not a validation check but a function to converts various sms formats into a common format for use in this module.
What we should be doing calling the sms_validate_number function here:
Comment #3
univate CreditAttribution: univate commentedComment #4
rjbrown99 CreditAttribution: rjbrown99 commentedI'm testing this with the email gateway and the send_form_validate is failing, even when sms_validate_number does not return an error. In this case, I get to sms_validate_number and it makes it through both checks successfully. Nothing is returned in that case since it wasn't an error.
Reverting the change from post #2 fixes this behavior. I'm not going to troubleshoot further, but I advise either backing out the change from #2 or enhacing the logic.
Comment #5
univate CreditAttribution: univate commentedComment #6
NROTC_Webmaster CreditAttribution: NROTC_Webmaster commentedI was having the same problem when trying to send a test message and what it seemed like to me was the actual validation called
sms.module line 604
What worked for me was to check and see if it had 9 or 10 digits instead
obviously this is a very simple test but I think it is a better test than what was there
Comment #8
dpi