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
0
votes
1 answer

yii2 validate related models

We have 2 models: Order OrderItems So when saving the related OrderItems I need to check some attributes from the parent Order. Order has attributes: "time_begin" and "time_end" and OrderItem has its own "time_begin" and "time_end". So the…
Vld
  • 3
  • 1
0
votes
1 answer

Yii2 validation triggering incorrectly on form with repeated model records

I have been working on this all day and this is the first time I have posted here so I hope someone can help me, please. I have a form where the multiple records for one form are the same model. As a result, I set manually the name and id tags. I…
0
votes
0 answers

yii2 :what is this error Bad Request (#400) in (delete every thing and sign up)

my site is correct in localhost but when my site uplaoded in host has this error :There was an error with your request.Bad Request (#400) i have error in delete every thing and create user in rbac and signup user! i used : rback and dekturim users…
Saltern
  • 1,305
  • 2
  • 16
  • 42
0
votes
1 answer

Yii2 exist validation rule on database transaction

One function in my model use the transaction to save a row in two distinct tables, table_1 and table_2. In table_2 one foreign key refers to table_1.id and the validation rule, auto generate by gii, is type "exist". When I need to save rows the…
0
votes
1 answer

validation is not working after setting scenario

my client side validation is not working after creating scenarios. it works fine before creating scenario . i have two scenarios update and create, i've two field to be required on create scenario and i've one field to be required on update…
Ajith Lal
  • 83
  • 2
  • 9
0
votes
1 answer

Function rules() doesn't work yii2

function rules not applied in my code, and I did the same code in the loginFrom model but it worked well ! here is my model
shrouk mansour
  • 381
  • 3
  • 16
0
votes
2 answers

Data is not storing in the database in yii2

I have two models in my project Employee visa model and visa track model.I want to store the primary key of employee visa table(ie.,employee_visa_id) in employee_visa_id field of the next table visa track. The roles of visa track is: public function…
Dijo
  • 73
  • 2
  • 10
0
votes
0 answers

Split single form into multiple tabs with next/previous button in Yii2

I want to incorporate tabs in my form(it is dependent on multiple models) with next and previous button, and onclick of these buttons should validate the fields with comes only in their respective tabs but form should be submitted/saved to DB only…
Rachna
  • 39
  • 13
0
votes
1 answer

How to Check which validation is violated for a model in Yii2

when I print ths statement inside a model as, Yii::error($this->validate()); it gives me false QUESTION : How can I check which validation is getting violated? As I have 38 parameters with different rules, I am tired debugging application. any…
Ankur Soni
  • 5,725
  • 5
  • 50
  • 81
0
votes
2 answers

Yii2 as beforeRequest authentication rule in config not working for pages

In a Yii2 advance application, I am trying to allow users to the login page and about page only. So i put in the /common/config/web.php configuration file the following rule 'as beforeRequest' => [ //if guest user access site so, redirect to…
0
votes
1 answer

Yii2. Date validation rule wrong format

I have such validation rule ['birthdate', 'date', 'format' => 'Y-m-d'], and passing such value 2002-03-11, but recive validation error The format of Birthdate is invalid. What am I doing wrong?
D.R.
  • 2,540
  • 3
  • 24
  • 49
0
votes
1 answer

In YII2 validation rules I need something opposite to compare

I need to compare new password with old one that they are unequal it`s a code where new password and password confirm compares, but what I can do for my matter? ['password_confirm', 'compare', 'compareAttribute'=>'password_new', 'message'=>"пароль и…
Vadik
  • 3
  • 4
0
votes
1 answer

How to set date format depending on incoming other attribute value in Yii2 model

I want to save Task model, but cannot do it without define date. I have boolean attribute allDay (checkbox in view) and if it set in TRUE date format should be d-m-Y; else 'd-m-Y H:m'. How to define this condition in rules() method? Next code not…
Oleg Sg
  • 5
  • 4
0
votes
0 answers

yii2: Backend login makes website go down. Temporarly

At first 1 month when the website was uploaded, both backend and frontend worked fine. Then without any coding changes to the application, frontend is working fine, whenever I tried to login to backend, error pops like "the page isn't redirecting…
0
votes
0 answers

accessing another model value in beforeSave() in yiii2

A model fields and B model fields in same form Ex: public static function tableName() { return 'a'; } public function rules() { return [ [['id','b_id'], 'id'], ]; } public function beforeSave($insert) { //I want to save b…
Yasar Arafath
  • 605
  • 1
  • 9
  • 30