All Projects → Borales → Yii2 Phone Input

Borales / Yii2 Phone Input

Licence: other
Yii2 International telephone numbers

Projects that are alternatives of or similar to Yii2 Phone Input

Config
Yii2 application runtime configuration support
Stars: ✭ 54 (-52.63%)
Mutual labels:  yii2, yii2-extension
Admin
Admin pack (actions, widgets, etc) for Yii2
Stars: ✭ 100 (-12.28%)
Mutual labels:  yii2, yii2-extension
Php frameworks analysis
php框架源码分析
Stars: ✭ 57 (-50%)
Mutual labels:  yii2, yii2-extension
Yii2 Social Share
With this extension you can share data from your web pages to any social network!
Stars: ✭ 48 (-57.89%)
Mutual labels:  yii2, yii2-extension
Ar Position
ActiveRecord behavior, which provides ability for custom records order setup
Stars: ✭ 107 (-6.14%)
Mutual labels:  yii2, yii2-extension
Yii2 Rabbitmq
RabbitMQ Extension for Yii2
Stars: ✭ 52 (-54.39%)
Mutual labels:  yii2, yii2-extension
Sitemap
Site map creation support
Stars: ✭ 59 (-48.25%)
Mutual labels:  yii2, yii2-extension
Yii2 Relation Trait
Yii 2 Models add functionality for load with relation, & transactional save with relation PLUS soft delete/restore feature
Stars: ✭ 47 (-58.77%)
Mutual labels:  yii2, yii2-extension
Yii2 Migrik
Yii2 Gii-tools for create migration files
Stars: ✭ 99 (-13.16%)
Mutual labels:  yii2, yii2-extension
Yii2 Jwt
JWT implementation for Yii2 Authorization process
Stars: ✭ 61 (-46.49%)
Mutual labels:  yii2, yii2-extension
Yii2 Gallery Manager
Stars: ✭ 90 (-21.05%)
Mutual labels:  yii2, yii2-extension
Csv Grid
Yii2 extension for CSV export
Stars: ✭ 83 (-27.19%)
Mutual labels:  yii2, yii2-extension
Yii2 Editable
Editable widget and column for gridview.
Stars: ✭ 47 (-58.77%)
Mutual labels:  yii2, yii2-extension
Yii2 Aws S3
An Amazon S3 component for Yii2
Stars: ✭ 86 (-24.56%)
Mutual labels:  yii2, yii2-extension
Yii2 Lifecycle Behavior
Define the lifecycle of a model by defining allowed status changes.
Stars: ✭ 47 (-58.77%)
Mutual labels:  yii2, yii2-extension
Yii2 Psr Log Target
Yii 2.0 log target that is able to write messages to PSR-3 compatible logger
Stars: ✭ 58 (-49.12%)
Mutual labels:  yii2, yii2-extension
Yii2 Gravatar
Gravatar Widget for Yii Framework 2
Stars: ✭ 36 (-68.42%)
Mutual labels:  yii2, yii2-extension
Yii2 Cms
Simple CMS extension
Stars: ✭ 42 (-63.16%)
Mutual labels:  yii2, yii2-extension
Yii2 Collection
Collection extension for Yii 2
Stars: ✭ 62 (-45.61%)
Mutual labels:  yii2, yii2-extension
Yii2 Schemadump
Generate the schema from an existing database.
Stars: ✭ 78 (-31.58%)
Mutual labels:  yii2, yii2-extension

Yii2 International telephone numbers - Asset Bundle, Behavior, Validator, Widget

Latest Stable Version Total Downloads Latest Unstable Version License Build Status

This extension uses 2 libraries:

Original demo can be found here - http://jackocnr.com/intl-tel-input.html.

Installation

The preferred way to install this extension is through composer.

Either run

$ php composer.phar require "borales/yii2-phone-input" "*"

or add

"borales/yii2-phone-input": "*"

to the require section of your composer.json file.

Usage

Phone input

Using as an ActiveField widget with the preferred countries on the top:

use borales\extensions\phoneInput\PhoneInput;

echo $form->field($model, 'phone_number')->widget(PhoneInput::className(), [
    'jsOptions' => [
        'preferredCountries' => ['no', 'pl', 'ua'],
    ]
]);

Using as a simple widget with the limited countries list:

use borales\extensions\phoneInput\PhoneInput;

echo PhoneInput::widget([
    'name' => 'phone_number',
    'jsOptions' => [
        'allowExtensions' => true,
        'onlyCountries' => ['no', 'pl', 'ua'],
    ]
]);

Using phone validator in a model (validates the correct country code and phone format):

namespace frontend\models;

use borales\extensions\phoneInput\PhoneInputValidator;

class Company extends Model
{
    public $phone;

    public function rules()
    {
        return [
            [['phone'], 'string'],
            [['phone'], PhoneInputValidator::className()],
        ];
    }
}

or if you need to validate phones of some countries:

namespace frontend\models;

use borales\extensions\phoneInput\PhoneInputValidator;

class Company extends Model
{
    public $phone;

    public function rules()
    {
        return [
            [['phone'], 'string'],
            // [['phone'], PhoneInputValidator::className(), 'region' => 'UA'],
            [['phone'], PhoneInputValidator::className(), 'region' => ['PL', 'UA']],
        ];
    }
}

Using phone behavior in a model (auto-formats phone string to the required phone format):

namespace frontend\models;

use borales\extensions\phoneInput\PhoneInputBehavior;

class Company extends Model
{
    public $phone;

    public function behaviors()
    {
        return [
            'phoneInput' => PhoneInputBehavior::className(),
        ];
    }
}

You can also thanks to this behavior save to database country code of the phone number. Just add your attribute as countryCodeAttribute and it'll be inserted into database with the phone number.

namespace frontend\models;

use borales\extensions\phoneInput\PhoneInputBehavior;

class Company extends Model
{
    public $phone;
    public $countryCode;

    public function behaviors()
    {
        return [
            [
                'class' => PhoneInputBehavior::className(),
                'countryCodeAttribute' => 'countryCode',
            ],
        ];
    }
}

Note: nationalMode option is very important! In case if you want to manage phone numbers with country/operator code

  • you have to set nationalMode: false in widget options (for example, PhoneInput::widget(...options, ['jsOptions' => ['nationalMode' => false]])).
Note that the project description data, including the texts, logos, images, and/or trademarks, for each open source project belongs to its rightful owner. If you wish to add or remove any projects, please contact us at [email protected].