misd-service-development / phone-number-bundle

Integrates libphonenumber into your Symfony2-Symfony4 application
459 stars 143 forks source link

My form submission is always invalid #198

Open Evertt opened 5 years ago

Evertt commented 5 years ago

I have an entity that uses the phone number type:

/**
 * @ORM\Column(type="phone_number")
 * @AssertPhoneNumber
 */
private $phone;

I have a form that uses the phone number type:

->add('phone', PhoneNumberType::class)

But when I submit the form, it's always invalid. And I think it's because when I type in something like +31612345678 (which is a valid phone number) then it transforms that into the text Country Code: 31 National Number: 612345678 before passing it to the validator.

That's gotta be a bug, right? Please help. 🙏

Evertt commented 5 years ago

Sorry, my mistake. I still had these functions in my entity

public function getPhone(): ?string
{
    return $this->phone;
}

public function setPhone(string $phone): self
{
    $this->phone = $phone;

     return $this;
}

which converted the phone number to string...

Evertt commented 5 years ago

Hmm, something is still not right. Right now it seems to work properly when I try to validate Dutch phone numbers, but when I try to validate Nigerian phone numbers it still doesn't work. And our app is actually made for Nigerians.

Have any of you ever tried to validate Nigerian phone numbers and tried if it worked?

BThiebaut commented 4 years ago

Hi, I also have a lot of problems with the validation using ethiopian numbers or other with 3 numbers on the indicator. For now I solve it by overriding the Validator to make it more flexible, but for long terms it's not viable.

I will consider moving on another repo like https://github.com/odolbeau/phone-number-bundle , this one seems not to be maintained anymore.