phone-number-bundle icon indicating copy to clipboard operation
phone-number-bundle copied to clipboard

My form submission is always invalid

Open Evertt opened this issue 6 years ago • 3 comments
trafficstars

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 avatar Apr 23 '19 15:04 Evertt

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 avatar Apr 23 '19 15:04 Evertt

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?

Evertt avatar Apr 23 '19 16:04 Evertt

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.

BThiebaut avatar Dec 06 '19 13:12 BThiebaut