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.

150 questions
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,421
  • 3
  • 16
  • 39
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
  • 542
  • 6
  • 20
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
  • 43
  • 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
  • 571
  • 8
  • 25
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
  • 83
  • 2
  • 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 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
vote
2 answers

Yii2 REST: How to customize Error response?

For first I use this solution - http://www.yiiframework.com/doc-2.0/guide-rest-error-handling.html But, I want to customize two types error. When model validation wrong. When something wrong (Exceptiin) If model validation wrong i get response,…
1
vote
1 answer

Disable ActiveForm Clientside Validation on button other than submit Yii2

I have an upload excel to DB form. It has 1 File input and 2 buttons 'Upload' and 'Delete All'. Problem Scenario: I don't want client-side activeform validation on 'Delete All' as File is not required here. Code:
Ankur Soni
  • 4,597
  • 4
  • 32
  • 63
1
vote
1 answer

Custom login form Yii2 Basic

I try to make custom login form in Yii2 Basic , without the ActiveForm widget . I made form which I want to use for login but , when I try to login it doesnt login only refresh the page without nothihng, so maybe I miss something or dont do like it…
RosS
  • 317
  • 1
  • 5
  • 23
1
vote
2 answers

Yii2 When Validation

Out of two pairs of input fields I only need one or the other. I can't get the validation right. listing_image_url and poster_image_url should only be required if $model->listingImage is null. Also tried using strlen($model->listingImage) == 0. …
Ciprian
  • 2,567
  • 5
  • 48
  • 85
1
vote
1 answer

Foreign key validation rule in Yii2

I have parent_id that can have NULL value - default sets to 0. Model ... [['parent_id'], 'integer'], [['parent_id'], 'default', 'value' => 0], [['parent_id'], 'exist', 'targetAttribute' => 'id', 'skipOnEmpty' => true], ... But exist rule didn't…
Marsick
  • 118
  • 1
  • 11
1 2
3
9 10