2017 © Pedro Peláez
 

yii2-validators yii2-validators

Set of validators that doesn't exist in Yii by default

image

bitdevelopment/yii2-validators

Set of validators that doesn't exist in Yii by default

  • Tuesday, July 11, 2017
  • by crnimilos
  • Repository
  • 1 Watchers
  • 0 Stars
  • 54 Installations
  • PHP
  • 0 Dependents
  • 0 Suggesters
  • 1 Forks
  • 0 Open issues
  • 2 Versions
  • 0 % Grown

The README.md

yii2-validators

Yii2-validators are validators for yii for some specific cases that are not covered by standard yii2 validators. Currently it holds 2 validators but will be extended in future. - WordCount Validator - ReCaptcha Validator and InputWidget, (*1)

Recaptcha validator and InputWidget is having new features: - Compatible with Pjax - Added ability to have more than one ReCaptcha widget on same page, (*2)

Installation

The preferred way to install this extension is through composer. Check the composer.json for this extension's requirements and dependencies., (*3)

To install, either run, (*4)

$ php composer.phar require bitdevelopment/yii2-validators "v1.1.0"

or add, (*5)

"bitdevelopment/yii2-validators": "v1.1.0"

to the require section of your composer.json file., (*6)

Latest Release

NOTE: The latest version of the module is v1.1.0., (*7)

Usage

WordCount Validator

Add validator to your rules list in your model, (*8)

use bitdevelopment\yii2validators\WordValidator;

class Post extends \yii\base\Model {

  public function rules() {
    return [
            [['myField'],WordValidator::className(),'min'=>200,'max'=>500]
    ];
  }
  ...

If you want to validation occurs while user is typing you can use validateOnType option, for example:, (*9)

$form->field($model, 'comment',['validateOnType' => true])->textarea([
                    'rows'=> 15
            ]);

Since version v1.1.0 stripTags feature has been added, that strips HTML tags before it counts words, by default stripTags is setup to false., (*10)

ReCaptcha Validator and Widget setup

There are two ways of setting ReCaptcha Validator in your project, one is inline setup, if you decide to use multiple key:secret pairs and setup in your params.php file if you have global setup, (*11)

Setting up in params

In your params.php file of your project setup new key so it will look like this:, (*12)

return [
       /*
    * Your params...
    */
    'reCaptcha' => [
            'siteKey' => 'site_key',
            'secret' => 'secret_key',
        ],
];

Note that site_key and secret_key you can obtain on your Google ReCaptcha Admin., (*13)

Now let's setup validation in your Model:, (*14)

use bitdevelopment\yii2validators\ReCaptchaValidator;

class Post extends \yii\base\Model {

  public $reCaptcha;

  public function rules() {
    return [
            [['reCaptcha'], ReCaptchaValidator::className()],
        [['reCaptcha'], 'required'],
    ];
  }
  ...

And Last step is to setup inputWidget on your view file, where your form is:, (*15)

echo $form->field($comments, 'reCaptcha')->widget(
                bitdevelopment\yii2validators\ReCaptcha::className(),
        )->label(false) ?>
Inline Settings

Similarly like when setting up with params.php you can setup params inline against a field, like in this example:, (*16)

  //In your rules
  [['reCaptcha'], ReCaptchaValidator::className(),'secret'=>'secret_key'],
  ...
  //In your view
  echo $form->field($comments, 'reCaptcha')->widget(
                bitdevelopment\yii2validators\ReCaptcha::className(),
        ['siteKey','site_key']
        )->label(false) ?>

The Versions

11/07 2017

dev-master

9999999-dev https://github.com/bitdevelopment/yii2-validators

Set of validators that doesn't exist in Yii by default

  Sources   Download

BSD-3-Clause

The Requires

 

by Milos Radojevic

extension yii2 form widget validators word count dependent

11/07 2017

v1.1.0

1.1.0.0 https://github.com/bitdevelopment/yii2-validators

Set of validators that doesn't exist in Yii by default

  Sources   Download

BSD-3-Clause

The Requires

 

by Milos Radojevic

extension yii2 form widget validators word count dependent