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
1
vote
1 answer

Set unique rule to a field on update action on yii2 rest

I am creating a rest api with yii2 to create and update user information. Below is the rule function in the model class. public function rules() { return [ [['name', 'emailId', 'contactNumber'], 'required'], …
Mahendran Sakkarai
  • 8,381
  • 6
  • 44
  • 66
1
vote
3 answers

Yii2 - custom validation with db query

I am trying to make this custom validation works, but I am not getting anything at the moment. What seems to be the problem? ['password', function($attribute, $params){ $password = \Yii::$app->db …
Sasha
  • 8,521
  • 23
  • 91
  • 174
1
vote
2 answers

Yii 2 FileValidator

I'm new to Yii 2 and reading the documentation and experimenting. Using the ActiveForm and trying to do a file upload, I keep getting an error "Please Upload a file" even though it appears that a file has been uploaded when I step through the code.…
1
vote
0 answers

Unable to verify your data When I try send a form with Yii2 advance

I get this error when I try use some of the forms. (Login or signup). I searched on the web, but I dont see any response (I dont want disable the csrf flag) In signup form, for example, I send the next…
Genaut
  • 1,810
  • 2
  • 29
  • 60
1
vote
1 answer

yii2 retype password not working

I am try to implement retype password field in my registration form. but unfortunately i didn't work for me. please help me. public $repeatpassword; public function rules() { [['Fname','Lname','username','email', 'password'],…
asela daskon
  • 496
  • 1
  • 8
  • 21
1
vote
5 answers

yii2 custom validation not working

I need to compare 2 attribute value in the model and only if first value is lower than second value form can validate.I try with below code but it not worked. controller public function actionOpanningBalance(){ $model = new Bill(); if…
Rumes Shyaman
  • 1,072
  • 1
  • 15
  • 30
1
vote
4 answers

Yii2 GridView search dependent dropdown

I am using Yii2 gridview to load country, state,city. I have set search option for country, state, city using dropdown. How do I create dependent dropdown in filter? $dataProvider, 'filterModel' =>…
JeevaRekha
  • 383
  • 1
  • 7
  • 21
1
vote
0 answers

Yii2 Standalone file Upload

I'm trying to upload a profile picture without ActiveForm or Model. According to Yii2 docs we can use AdHoc Validation Rule, In this example it's using email validation but i need file validation. What i've tried: public function actionPicture() { …
Touqeer Shafi
  • 5,084
  • 3
  • 28
  • 45
1
vote
0 answers

Have trouble when using Yii2 multilang behavior

I'm using Multilang-behavior But, when clicking on the update button to view data, data is returning id = 1. This is my code in controller: public function actionUpdate($id) { $model = Post::find()->multilingual()->one(); //$model =…
luongit
  • 117
  • 2
  • 13
1
vote
1 answer

How to validate data to unique when the data is changed on update

I have books table and isbn field in it. When the user update existing book, if he changes the isbn code and save, isbn should be checked to unique, otherwise unique validation must be skipped. There's unique validation but it is checking even isbn…
Sarvar Nishonboyev
  • 12,262
  • 10
  • 69
  • 70
0
votes
1 answer

Yii2 Validation not working on the when condition

Scenario $scenarios['sell'] = [ 'deposit']; Rule ['deposit', 'required', 'on' => 'sell', 'message' => 'Deposit cannot be blank', 'when' => function () { if (Yii::$app->controller->id == 'transaction'…
Shamnad
  • 35
  • 5
0
votes
1 answer

How to upload images with tabular input in Yii2?

I´m struggling with tabular input and image upload. I´m not using any extensions/widgets. Form works perfectly, but - without image upload. I created 2 models: EventForm (single form) and EventArtwork (can be multiple) I have a function protected…
0
votes
1 answer

validation not working upon click submit in Yii2 Php Framework

I created a simple form with simple rules declared in model, but when I tried to submit, It is not working, I don't encountered an error also. The expected output should be the session flash, but nothing happened in my case This is my…
0
votes
0 answers

Yii2 Captcha Image Not showing on main page. controller/captcha link shows image just fine

I am working on a page that allows users to track orders that they have placed in our system. To prevent Spam, I am wanting to add a captcha to the page. I am using Yii2 for this. For some reason the captcha image is not showing up. I can visit…
0
votes
0 answers

Yii2 login not working properly on remote server

I have a login problem on the remote server. I followed the error and discovered that the user is logged in this returns true in the LoginForm and at this level, I have the user Yii::$app->user->login($this->getUser(), $this->rememberMe ? 3600 * 24…
leila
  • 461
  • 1
  • 7
  • 21