Questions tagged [yii2-validation]

Use this tag if your question relates to the Yii2-validation-system, no matter if your validation is within a model or as standalaone validator-instances.

This tag is about the Yii2-validation-system. In most cases validators get used within models to validate their properties (rules()-method). However, you can also use all the validators as standalone instances or create your own inline-validators.

The basic usage of Yii2's validators is very well documented in the corresponding section of the official guide.

150 questions
3
votes
2 answers

Protected Directory existence and creating custom validator in Yii2

I was searching for password strength meter for Yii2. I found this article for Yii1. I saw protected directory mention there. I'm unable to find this folder. Is it available in Basic Application Template or Advanced Application Template?
Nana Partykar
  • 10,175
  • 8
  • 43
  • 73
3
votes
2 answers

Yii2, custom validation: clientValidateAttribute() doesn't work correctly

I have form, created by ActiveForm widget. User enters polish postal code there. In appropriate controller I put entered data in DB, for example: $company_profile_data->postal_code =…
Boolean_Type
  • 953
  • 2
  • 12
  • 32
2
votes
1 answer

how to place yii2 form error in title of anchor tag

how to place yii2 form error in title of anchor tag This is my code $form = ActiveForm::begin([ 'id' => 'login-form', 'options' => ['class' => 'form-horizontal'], 'fieldConfig' => [ 'template' => ' {label} …
2
votes
1 answer

Yii2 unique validator ignored

In the rules() of my RegisterForm model: [ 'user_username', 'unique', 'targetClass' => 'app\models\User', 'message' => 'This username is already been taken.' ], In my controller: $model = new RegisterForm(); if ( $model->load(…
keeg
  • 3,860
  • 8
  • 44
  • 92
2
votes
2 answers

Validate Yii2 Activeform on simple button click

I want to validate my Yii2 activeform on simple button click which is not submitButton. I tried $('#formId').yiiActiveForm("validate") but it is not working. I also tried - $('#formId').yiiActiveForm('submitForm') it validates form but it also…
Vinit Singh
  • 1,113
  • 2
  • 21
  • 45
2
votes
1 answer

yii2 password rules pattern

you can at yii2 in the Model Rules enter patterns in passwords ? Tips for a rule that at least one uppercase character and at least one number ? Thanks so much Rules ['password', 'pattern' => '(?=.*\d)(?=.*[a-z])(?=.*[A-Z])(?=.*[@#$%]).{6,20}'],
Saba
  • 105
  • 1
  • 12
2
votes
1 answer

Regex yii2 phone number validator

I'm trying to validate the following phone numbers using Regex validator in yii2: +6018-2031218 0060182031218 006018-2031218 like this public function rules() { return [ [['name', 'minimum_order_amount', 'time_order_open',…
Fadi
  • 1,997
  • 6
  • 27
  • 68
2
votes
1 answer

Yii2 required validator in an array field

In my code i have a field (e.g field name is exampleField[]) in which i implemented add more functionality through JS .Now , i want to implement Yii2 required Validtor on each field. I already use each validator but it's not working. My yii2 version…
SAR
  • 57
  • 8
2
votes
2 answers

Yii2 Unique Validator not working when insert so fast

I am using ActiveRecord model to save data. Unique Validator works very perfect. But when i insert data so fast, it no longer works perfectly. In some request i get error that it can not catch by Yii. Integrity constraint violation –…
Ngô Văn Thao
  • 3,085
  • 1
  • 18
  • 22
2
votes
0 answers

Yii2 oauth2 client_credential token authentication

I use Filsh/yii2-oauth2-server, I can use client token using $_pos to access my API. In controller: if (!isset($_post['token'])){ //exeption } else{ token = $_post('token'); } if ((Accesstokens::isAccessTokenValid($token))) { // do some thing. } in…
Jimmy
  • 21
  • 1
2
votes
1 answer

Validating unique email using DynamicFormWidget - Yii2

I am using DynamicFormWidget for multiple input fields like: first_name, last_name, email & mobile_no. And, I don't want user to type the existing email. Means, email should be unique. It is working when I am not using DynamicFormWidget. Actually, I…
Nana Partykar
  • 10,175
  • 8
  • 43
  • 73
2
votes
1 answer

Yii2 Validation rule: How to check datetime and place does not collidate with another entry?

This is my table event As you see Transaction 1 time_begin: 2016-03-10 07:00:00 time_end: 2016-03-10 08:00:00 place: 1 If user makes a Transaction 2 and then selects time_begin: 2016-03-10 07:15:00 time_end: 2016-03-10…
2
votes
3 answers

Yii2 validate Bank Account number and Routing number

I want to validate Bank Account number(123456789) and Routing number(434344343), with custom message=>Please enter 12 digit valid account number.(000123456789) I used number validator, integer but not working as I expecting. Validator should checks…
Muhammad Shahzad
  • 7,778
  • 20
  • 71
  • 123
2
votes
1 answer

Yii2: compare validation of password and repassword

I'm a beginner of Yii, that's why can't figure out, what's wrong. I use the same model - Users - for login, registration and edition profile. Users model: class Users extends \yii\db\ActiveRecord { public $password_repeat; //have no this value…
Boolean_Type
  • 953
  • 2
  • 12
  • 32
1
vote
1 answer

use "when" in nested yii2 EachValidator

is there a way to use the when attribute in nested EachValidator? Here is my rule but it does not work: [['list'], 'each', 'rule' => ['required', 'when' => function ($model) {return false;}, 'whenClient' => "function (attribute, value) {return…
EvilKarter
  • 257
  • 7
  • 21
1
2
3
9 10