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
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
  • 5,725
  • 5
  • 50
  • 81
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
  • 2
  • 6
  • 24
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
  • 3,066
  • 9
  • 62
  • 98
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
  • 138
  • 1
  • 11
1
vote
0 answers

Yii2 ActiveForm radioList required value verification

I implented a form using the Yii2 activeForm field, but can't get the form to submit. I keep getting the verification error "Payment Method cannot be blank" from the model, I set the payment method as a required value, but somehow the value from the…
1
vote
2 answers

Message for unique validator is not coming in yii2

I have following rule for email to be unique in modal [['email'], 'unique'], I am not using ajax to submit form. Problem is that I am getting all rules validation messages except unique rule. So how to make unique rule work at client end? What…
alwaysLearn
  • 6,882
  • 7
  • 39
  • 67
1
vote
2 answers

Yii2, Form and field names

Simple question but no solution yet. As we know 'get']); ?> field($formFilter, 'keyword') ->textInput(['placeholder' => \Yii::t('', 'keyword')]); ?> ... will create simple form and…
user1954544
  • 1,619
  • 5
  • 26
  • 53
1
vote
1 answer

Required field not working after including pattern in name - Yii2

I'm passing through awkward situation. All rules working fine except required field for first_name. 'FirstNameLength' => ['first_name', 'string', 'min' => 3, 'tooShort'=>'First name should contain atleast 3 character'], 'FirstNameTrim' =>…
Nana Partykar
  • 10,556
  • 10
  • 48
  • 77
1
vote
2 answers

Disable Yii Validation Error Message on focus / key up - Yii2

As default, error message coming on keyup and after pressing submit button in form (If any error exist for that particular attribute). Which Is Ok. Working perfectly fine. But, Is it possible to disable error message on key up? Means, error…
Nana Partykar
  • 10,556
  • 10
  • 48
  • 77
1
vote
2 answers

Yii2 : - Require one error message for three fields

I have three dropdowns for day, month, and year. when I applied required condition yii2 validation show individual error for all three fields. But I want single error message for three fields like "dob is required". view file :
garima
  • 31
  • 3
1
vote
0 answers

I'm sending _csrf token in form but still i am getting #400 unable to verify data submission in yii2

I'm sending _csrf token in form even in ajax post but still i am getting #400 unable to verify data submission in yii2. I don't want to use the following code to avoide this issue: public function beforeAction($action) { …
1
vote
1 answer

yii2 null value in dropdownlist

I have a dropdown list in an active form i display the data correctly but when I want to insert the value of the selected value of the dropdownlist the value is null. In my controller : $model = new AjoutRessourceForm(); if…
Samaël Villette
  • 318
  • 3
  • 25
1
vote
1 answer

Yii2 - validation compare acting strange

Compare validation is action strange - no matter what, emails are never the same, and error is shown all the time. This is the code for validation: public function rules() { return [ [['first_name', 'last_name', 'email',…
Sasha
  • 8,521
  • 23
  • 91
  • 174
1
vote
1 answer

Yii2 advanced login from the same view to frontend and backend

I've got a question about Yii2. It is possible to login from frontend and be redirected to backend if login user is admin ? I've got two configured localhost addresses like: www.test.loc/ <-- this is path to frontend/web www.admintest.loc <--…
rafaa1994
  • 71
  • 3