adt / nette-forms-phone-number
Installs: 22 700
Dependents: 0
Suggesters: 0
Security: 0
Stars: 3
Watchers: 14
Forks: 1
Open Issues: 0
Requires
- brick/phonenumber: ^0.4 | ^0.5
- geoip2/geoip2: ^2.10
- nette/forms: ^2.4 | ^3.0
README
Installation
Install library via composer:
composer require adt/nette-forms-phone-number
and register method extension in bootstrap.php
:
\ADT\Forms\Controls\PhoneNumberInput::register();
This allows you to call the method addPhoneNumber
on class Nette\Forms\Form
or Nette\Forms\Container
.
Usage
It's very simple:
$form->addPhoneNumber('phone', 'Phone number') ->setCountryCodeItems(['+420' => '+420']) // otherwise lists all countries with a prompt ->setDefaultCountryCode('+420') // otherwise set by geo IP address ->setRequired('Fill your phone number') ->addRule(PhoneNumberInput::VALID, 'A phone number must be valid') ->addRule(PhoneNumberInput::TYPE, 'A phone number must be mobile', PhoneNumberType::MOBILE); $form->onSuccess[] = function ($form) { $form['phone']->getValue(); // returns instance of Brick\PhoneNumber\PhoneNumber $form['phone']->getValue()->getCountryCode(); // returns eg. "+420" $form['phone']->getValue()->getNationalNumber(); // returns eg. "776123123" };
And in latte:
{input phone}
or separately:
{input phone:countryCode} {input phone:nationalNumber}
To turn on autocomplete in IDE, add @method PhoneNumberInput addPhoneNumber($name, $label = null)
to your base form.