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 form validation and image upload component

I use Yii2 framework and implemented the form that contains plain input fields and one component for image upload. Everything works fine when I first time upload the image but when I reopen the previously saved data in the form - it shows me the…
alexanoid
  • 24,051
  • 54
  • 210
  • 410
0
votes
1 answer

Understanding Yii2 "range" validation rule

I am new to Yii2 Framework and I need to understand the users status. I need to create an app that assign many statuses to the user, comparing to just 2 that Yii2 gave. In Yii2 common\models\Users there are two constants: STATUS_DELETED = 0; and…
sam
  • 853
  • 3
  • 19
  • 50
0
votes
0 answers

Yii2 uploadfile image from model method beforeSave

i try to upload 4 or less images, the ajax validation do not return any error, but on submit i get the follow: "errors": { "imageFiles": [ "Please upload a file." ] } attr: /** * @var UploadedFile[] */ public $imageFiles; Rules: return…
0
votes
0 answers

captcha not working using scenarios in yii2

I am trying to add captcha validation based on scenario, for which I am first retrieving number of failed attempts from database. For which I am using checkattempts() function. Based on the result I am displaying captcha in view and adding scenario…
rji rji
  • 697
  • 3
  • 17
  • 37
0
votes
1 answer

How to add captcha required only for a particular condition yii2

I am trying make the captcha field required only when the number of failed login attempts exceed 3 times. For which I have written below code till now. In LoginForm model I have added the below rules public function rules() { return [ …
rji rji
  • 697
  • 3
  • 17
  • 37
0
votes
1 answer

yii2 assets not loading

Yii2 $depends not loaded CSS and Js file. public $depends = [ 'yii\web\JqueryAsset', 'yii\web\YiiAsset', 'yii\bootstrap\BootstrapAsset', ]; Above code not load js and CSS file when page load.Please, anyone, help me to shoot this…
Pramod kushwaha
  • 449
  • 6
  • 17
0
votes
1 answer

Yii2- match pattern not working properly

I have a column named imsi which is a string and I want to add only numbers in it so for that I used [['imsi'], 'match','pattern'=> '[0-9]','message'=>'IMSI must include only numbers'], Now, when I try to create a new record and insert the imsi…
Moeez
  • 494
  • 9
  • 55
  • 147
0
votes
1 answer

Yii2: how to call yiiActiveForm() manually?

In yii2 I have put all my js code in 1 file using yii2-assets-auto-compress plugin, including jQuery lib. Loading this file is async to speed up page load. But, if there are forms on the page, yii adds yiiActiveForm() at the end of . So, the…
sirjay
  • 1,767
  • 3
  • 32
  • 52
0
votes
1 answer

Yii2 validation rule for select field

I have a model, for example SomeForm. There is a field. This field contains an array of selected options. Is it possible to write a rule for this field to check how many items were selected? I need to write a condition, that user has to check…
dr Anton
  • 125
  • 1
  • 7
0
votes
1 answer

yii2 Validation not working

I need to validate a value from another table both of them field type decimal if amount(model 1) moreover available(model2 DATA selected) model 1 rule public function rules() { return [ [['amount'], 'checkAvailable','skipOnEmpty'…
0
votes
2 answers

redirect to previous address "from which form data was submitted" with model in yii2

I have created a widget to render the form in layouts/main.php footer section. This is a widget file named common\widget\SubscriberFormWidget.php
0
votes
1 answer

Yii 2 signup does not save records

In first, sorry for my bad English, I am little bit tried... My problem is that, when iI want to create a new user everything goes well, but ActiveRecord does not save my new account. This is my first question.. don't realy know what to paste in…
user65748
  • 5
  • 2
0
votes
1 answer

yii2 rewrite model addError

this is original Model.php function public function addError($attribute, $error = '') { $this->_errors[$attribute][] = $error; } in my model property i want override this method in this way public function addError($attribute, $error = '') { …
Andrea Perdicchia
  • 2,786
  • 1
  • 20
  • 19
0
votes
2 answers

How to cache "exists" validation in Yii2

I'm trying to cache the db calls for Yii2 exists validation, but can't work out where to initiate it. Because I'm using a multi-model form with a lot of relations, the overhead is getting a little too much. Any ideas?
Tom Horwood
  • 398
  • 3
  • 13
0
votes
1 answer

Form doesn't get submitted in yii2

I'm using yii2 advanced app and im stuck at a point where my form doesn't get submitted. It refreshes and stays on the same page. There are no errors shown too. Here is the model code Countries.php
user6780526