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
2 answers

How to use javascript in Yii2 model class?

In a custom validation function in my model class. I need to use javascript code. for that i used registerJs function but i am getting error:- Calling to undefined function registerJs() I also tried calling it by including View class i.e.,…
Ninja Turtle
  • 1,293
  • 2
  • 24
  • 50
0
votes
1 answer

Call to a member function saveAs() on null (I can not update if I do not select an image)

I can not update if I do not select an image. What do wrong or I'm missing? This is a controller: if ($model->load(Yii::$app->request->post())) { $nameImage=$model->name; …
Juam
  • 11
  • 3
0
votes
2 answers

Validation rule that requires to select at least two options

I have following validation rule: ['dagen_ids', 'required', 'message' => 'Selecteer.', 'when' => function($model) { return $model->frequentie == 2; }] The attribute dagen_ids is an array thats being populated by a Select2 widget (multi-select).…
JK87
  • 379
  • 2
  • 12
  • 26
0
votes
2 answers

yii2 custom validation in rule not working

How to implement custom validation in yii2? My code in model rules is public function rules() { return [ [['product_price'], 'checkMaxPrice'] ]; } public function checkMaxPrice($attribute,$params) { if($this->product_price >…
kritika555
  • 183
  • 1
  • 4
  • 15
0
votes
1 answer

Yii2 Server side Ajax Validation inside the Modal Box

In my Modal box I want to check for unique email, which can be done only after submitting the form. When I trigger thee submit button the controller action will send me to create action in the controller because it will return unique email address…
Mohan Prasad
  • 682
  • 1
  • 9
  • 34
0
votes
1 answer

Yii2 Confirm Password not working

I am trying to build a signup form, it works fine when I dont use repeat password, it saves to the model, but when I use my repeat password it just does'nt let me save them in the database. My code is below. SimUser.php file public function rules() …
Mohan Prasad
  • 682
  • 1
  • 9
  • 34
0
votes
1 answer

yii2 validate form error on submit

My Problem : I'm trying to validate user input using on certain fields. I have created rules on certain fields. When submit the form, it display the error message in json format and stop there. Error that i got after submit the form sample…
kasmawati
  • 51
  • 2
  • 9
0
votes
2 answers

Yii2 date comparison not working inside rules()

I have a form, and a user have to enter a date of beginning and a date of ending. I'm using the compare attribute inside the rules method because the user can't enter a date of ending which is before the date of beginning. Here's my rules method…
0
votes
1 answer

Set Yii Scenario if checkbox is checked

I want to apply required validation on textfield if checkbox is checked otherwise not.i tried by scenario but it's not working, For form i am using 'bootstrap.widgets.TbActiveForm' my Yii version : 1.1.16-dev
0
votes
1 answer

Dynamic forms operations with data on generated forms? yii2

basically. I have a problem with 2 things: I'm using dynamic forms, the user can add as many as he needs to input all of the invoices at hand. I have a field (invoice_loadamount), i want to sum all of the invoice_loadamount fields. So if the user…
user4714953
0
votes
1 answer

How to make validations from a query to a table? yii2

my problem is: I have a form where i have select2 and the user can select from a dropdown list which is populated from a table, so, basically what i want to happen is that when the user tries to select a driver a validation rule will take place…
user4714953
0
votes
2 answers

Yii2 validation with XRegExp, \p{L} not working

I'm using Yii2 framework and I have a Validator that should do client-side validation. I have a regex that looks like this: /^[\\p{L}]+$/u for simplicity, but my actual regex is a bit more complicated, but the \p{L} part is what causes the…
datiKaa
  • 326
  • 2
  • 15
0
votes
1 answer

Yii2: How to validate a form with multiple instances of the same model

In my form I update more start and end dates from the same model at once. See the simplified form: $date): ?> field($date,"[$i]start"); ?>
Antonín Slejška
  • 1,980
  • 4
  • 29
  • 39
0
votes
2 answers

Yii2 change username on creation

I want my app to detect when a username is already taken and change it. In fact, when the user register himself he enter his last and first name and the username is lastName.firstName. How do I detect the username is already taken and how to change…
Samaël Villette
  • 318
  • 3
  • 25
0
votes
2 answers

reset password validation in Yii2

I have a form in which I am trying to reset the password. I have 3 fields password, changepassword and re-enterpassword. First I need to check whether the password field matches with database password. While user signup I have used the default Yii2…
rji rji
  • 697
  • 3
  • 17
  • 37