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.

155 questions
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
  • 1,146
  • 3
  • 13
  • 40
1
vote
0 answers

I use the built-in captcha widget ii 2, I want to do for non-validation

controller: public function actions() { return [ 'error' => [ 'class' => 'yii\web\ErrorAction', ], 'captcha' => [ 'class' => 'app\captcha\CaptchaAction', 'fixedVerifyCode' =>…
user20062193
1
vote
3 answers

Define multiple scenarios and validate with multiple scenarios in Yii 2 model

In model I have defined multiple scenarios: public function rules() { return [ [['in_quantity'], 'required','on'=>['stockIn']], [['out_quantity'], 'required','on'=>['stockOut']], ]; } Is it possible to use both scenario…
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
  • 267
  • 7
  • 22
1
vote
2 answers

Yii2 - Assign a "fix" condition

I am building an app, where an account can have many services, all the information is related to a service. In example: Account A has 3 services and each service has pages. In order to avoid someone modifying the service_id when saving a page, at…
Eduardo
  • 1,781
  • 3
  • 26
  • 61
1
vote
1 answer

Yii2 form validation - compare password repeat only when password field is filled

My form validation uses the following rules: [['password', 'password_repeat'], 'required'], ['password_repeat', 'compare', 'compareAttribute' => 'password', 'message' => "Passwords don't match"], How to write rules for password_repeat to compare it…
Masoud92m
  • 602
  • 1
  • 8
  • 24
1
vote
0 answers

yii2 role based scenario

I'm developing a yii2 rest api based app that has different roles of users (Admin, Customer, Shop, Service). I'm planning to use scenarios with one user database table contains union of fields that requires all roles. (80% is the same) I would like…
Bence
  • 63
  • 4
1
vote
2 answers

yii2 CSRF not validating host

One more issue I am facing my site is created in yii2 and CSRF is enabled but when I copy full form including csrf token and create new html file outside server and submit form from outside of server it accepting my form. What is the expected…
Anil Kumar
  • 701
  • 11
  • 28
1
vote
1 answer

Yii2 model custom validate method / function does not work

I want to validate my fine_amount against 2 input date. But it does not return any error. Without validating this method it saved data. I also looked into Yii2: how to use custom validation function for activeform? but for me no solution. Below…
Destroyer.0211
  • 113
  • 1
  • 3
  • 13
1
vote
2 answers

Yii2 how to create rule (filter) for all model's attributes?

It's boring to apply "trim" filter for each attribute in the model. Any idea does Yii2 have something like that: ['*', 'filter', 'filter' => 'trim'],
1
vote
2 answers

Yii2. Access control by roles. How can I add 'OR' condition?

I have a controller with the following access restriction: 'access' => [ 'class' => AccessControl::className(), 'only' => ['index', 'view', 'create', 'update', 'delete'], 'rules' => [ …
1
vote
2 answers

Yii2 how to save old informations to history-table?

thanks for all stackoverflow members, I learned a lot from here. I have a question about "beforeSave", I want save the old data to history-table in the database, for example if the user change anything I want save the old informations in the…
1
vote
1 answer

Yii2 cannot save model data in controller

I am trying to get value from title and I did but after pressing save button the title is not saving in database $model = new Translation(); if ($model->load(Yii::$app->request->post()) && $model->save()) { $getfromtitle =…
1
vote
2 answers

Client Validate array inputs in Yii2

I have many inputs without connect any models in my form like this: my view is this and I put this to show to other user to detect what is my problem
Amir Khoshhal
  • 107
  • 2
  • 11
1
vote
0 answers

Yii2 object oriented model API throwing error on execution

I am creating an api using Yii2 framework . But it throws error during its execution. BankDetailsController.php
user7408344
1 2
3
10 11