This is the error message I get when inputting unacceptable data into the phone number field, such as, letters or too many numbers. It would be helpful if the errors were human friendly.

I am using the US and Canada restriction. It works great if valid input is submitted.

Thank you!

Support from Acquia helps fund testing for Drupal Acquia logo

Comments

jessico’s picture

Any ideas on how to modify the module to create our own error messages?

rfsbsb’s picture

FileSize
698 bytes

Here's a patch to solve this.

rfsbsb’s picture

Status: Active » Needs review

Please review this patch.

seworthi’s picture

Per the "hook_field_validate" API (http://api.drupal.org/api/drupal/modules!field!field.api.php/function/ho...), this is what we should change line 156 to:

$errors[$field['field_name']][$langcode][$delta][] = array(
  'error' => 'phone_invalid_number', 
  'message' => t($country['error'], array('%value' => $value)),
);

And we should add this:

/**
 * Implements hook_field_widget_error().
 */
function phone_field_widget_error($element, $error, $form, &$form_state) {
  form_error($element, $error['message']);
}

This is what I did and it solved the issue.

jessico’s picture

I'm getting an error when I try to apply the patch:

[root@webdev phone]# pwd
/var/www/drupal/sites/all/modules/phone
[root@webdev phone]# patch < phone_error.patch
patching file phone.module
patch: **** malformed patch at line 17:

I have tried the -p1 and -p0 parameters, as well as 'git apply path/file.patch'

I'm trying to evaluate the patch to see what the issue is, but am still fairly new at code analysis. Maybe I am applying the patch incorrectly, but this has seemed to work in the past for other patches. Any ideas?

I sincerely appreciate your time and assistance!

rfsbsb’s picture

FileSize
744 bytes

As suggested by seworthi, I changed the patch to fit correctly to the API.

rfsbsb’s picture

Hi acissej, first you must checkout the latest version from repo (instructions here http://drupal.org/node/87303/git-instructions/7.x-1.x). Then you should download the patch and apply using the instruction in the link above in the section "applying a patch"

Hope it helps.

rfsbsb’s picture

FileSize
744 bytes

In fact this is the correct patch. Sorry.

jessico’s picture

The #8 patched worked great! I am very thankful for your help!

Just to offer clarification for anyone else who runs across this thread. I used the instructions linked in comment #7 to pull down the latest project code and apply the patch.

Much gratitude!

star-szr’s picture

FileSize
595 bytes

Rerolled patch - no longer removes the extra newline at the end of the file and applies cleanly to 7.x-1.x-dev with or without git.

5n00py’s picture

This patch fix the error, but validation only show error message and pass the wrong value....

mgifford’s picture

Status: Needs review » Reviewed & tested by the community

Looks good. I just applied this to the git repo and tested it.

It's much better, but I got it because I wanted to put in an area code only into the default content.

It would be nice if the (613) were already there so folks just had to type in the 555-1212 after it.

carajito’s picture

Errors:

  1. 1 in valid_int_phone_number() (line 42
  2. message in field_default_form_errors() (line 381
mgifford’s picture

Status: Reviewed & tested by the community » Needs review

Well, that's not good. What were you doing?

Can you give us some details so we can repeat it? This is for international phone numbers?

-enzo-’s picture

Rerolled patch #10 against branch 7.x.1.x

baronmunchowsen’s picture

Status: Needs review » Reviewed & tested by the community

#15 Works well for me.

flatfeat’s picture

#15 works great for me, too.

warmth’s picture

Is this patch going to be committed at least to the dev version? It's urgent!

5n00py’s picture

Status: Reviewed & tested by the community » Needs work

You shouldn't use any variables when calling t() function. Only string literals with placeholders.
See http://api.drupal.org/api/drupal/includes!bootstrap.inc/function/t/7

cmejo’s picture

Priority: Normal » Major

Hello. I am getting the same error as the OP when a user tries to register for my site including a South African phone #. I am validating against US & Canada though we have international users signup on our site and I didn't think they wouldn't be allowed to enter a non-US & Canada phone #. The phone # was written like this: 27215555555 (obviously different digits than the 5's).

According to the phone.info file, the version of phone-7.x-1.x-dev is from 2012-03-02.

I perused the README file and it does not confirm support for South African phone numbers though I notice in the phone.module file there is a line for South Africa.

This was brought to my attention by a user that emailed me through the contact form on our site. He gave me screenshots of his signup process and I went through each field to find the problem. I am very confident the problem lines with this module.

What do I need to do to solve this issue? Should I update to a newer dev version or apply one of these patches? Thank you.

cweagans’s picture

Assigned: Unassigned » rfsbsb
Status: Needs work » Reviewed & tested by the community

Technically, I shouldn't be okay with having a variable inside t() like that, but since we're already doing it and we're getting rid of a notice, I can accept this for now. Over to rfsbsb for final review and commit.

lotyrin’s picture

Status: Reviewed & tested by the community » Needs work

The patch doesn't apply.

lotyrin’s picture

Status: Needs work » Fixed

Because it's been applied!

rfsbsb’s picture

Indeed this patch has already been applied http://drupalcode.org/project/phone.git/commit/ab36332

cweagans’s picture

Sorry about that!

cmejo’s picture

Thanks all! I spoke with cweagans on IRC and he applied the patch. I should have updated this thread.

Status: Fixed » Closed (fixed)

Automatically closed -- issue fixed for 2 weeks with no activity.