Questions tagged [yii-validation]

31 questions
36
votes
8 answers

yii: how to make a unique rule for two attributes

I have a table like this: (id, name, version, text). (name, version) is unique key, how can i make a rule to validate this.
li meirong
  • 363
  • 1
  • 3
  • 4
23
votes
2 answers

Yii: validation rules that always apply except one scenario

I know that you can have a validation rule that applies only for one scenario: array('username', 'exist', 'on' => 'update'), Now i would like to know if it's possible to do the opposite: a rule that applies everytime except for a given scenrio? The…
darkheir
  • 8,844
  • 6
  • 45
  • 66
5
votes
1 answer

scenario for validation rules in yii

I was wandering is there any chance to use scenario for rules, in my model I have public function rules() { return array( array('delivery, firstNameBilling, lastNameBilling, addressBilling, cityBilling, countryBilling, …
Ime Prezime
  • 55
  • 1
  • 1
  • 4
4
votes
6 answers

how we can add rule in Yii model for input must be greater than 0

do anyone know how can I apply rule in Yii model for input must be greater than 0 value, without any custom approach .. like : public function rules() { return array( .... .... array('SalePrice', 'required',…
Shadman
  • 755
  • 2
  • 11
  • 19
4
votes
1 answer

It's possible extend AR relationships?

I'd like know if there are a way to create my own rules to AR relationships or extends the existent HAS_MANY, BELONGS_TO etc? Thanks.
GodFather
  • 3,031
  • 4
  • 25
  • 36
3
votes
2 answers

How to create scenario in Yii2 with no validation rules active?

I have MyEntity.php model. As a part of the model script, there are some rules and some scenarios defined: public function rules() { return [ [['myentity_id', 'myentity_title', 'myentity_content', 'myentity_date'], 'required'], …
delux
  • 1,694
  • 10
  • 33
  • 64
3
votes
1 answer

Yii2: scenarios() model method

There are 2 needed functions: set password when registering and change password, if user forgot it. When user signs up, password length must be at least 4 chars; when changes pass - at least 5 chars. View is common for registration and changing…
Boolean_Type
  • 1,146
  • 3
  • 13
  • 40
3
votes
1 answer

Yii validation: some errors are not displayed

Here is my rules method: public function rules() { $newRules = array( array('password_verification, valid_from, valid_until', 'required'), array('password_verification', 'length', 'min'=>6, 'max'=>32), …
Michaël
  • 1,120
  • 1
  • 15
  • 30
2
votes
2 answers

Yii: How do you abort model validation in the middle, after one of the rules returns FALSE?

In Yii framework, how do you abort any further validation after one of rules returns FALSE ? What I am trying to achieve is: 1) stopping unnecessary MySQL queries after we know that a model didn't pass the validation. 2) cleaner, easy to understand…
Sebastian
  • 709
  • 1
  • 8
  • 15
1
vote
3 answers

Unique email values from a Yii 1.1 dynamic form

I have a Yii form accept first name, last name and email from user. Using an add more link, users can add multiple rows of those three elements. For email validation, unique and required are set in model rules and everything works fine. I am using…
Tismon Varghese
  • 849
  • 1
  • 6
  • 17
1
vote
1 answer

YiiFramework - Code redundancy on model rule declaration

would like to ask if is there a way that I can group multiple rules in the model into 1 so that i can reduce the amount of codes especially on places where same attribute needed to be check on multiple rules... Below is how the rules declaration…
Kenny Yap
  • 1,317
  • 5
  • 17
  • 39
1
vote
1 answer

Yii: rules 'allowEmpty'=>true still raise 'cannot be blank'

I have a problem with CActiveRecord.rules public function rules(){ return array( array('photo_path', 'required', 'on'=>'insert'), array('photo_path', 'file', 'types'=>'jpg, gif, png', 'allowEmpty'=>true), ); } Photo_path…
qwetty
  • 1,238
  • 2
  • 10
  • 24
1
vote
3 answers

different rules for the same AR model in Yii

I have one model extending AR class with specific rules. But now i need to insert row into this table, but with other rules. Is i need to create other model with new rules, or it is possible to define orther rules?
user1279525
  • 539
  • 1
  • 6
  • 12
0
votes
2 answers

Model save mutiple records and validation rules

I have a case where user can select multiple values in the list box and save it to the database using model. Here is the table structure user_id int(11) , cars_id int(5) Here is the snippet of my view
Bujji
  • 1,717
  • 10
  • 41
  • 66
0
votes
1 answer

email unique validator yii2 doesn't return message validation

I am try to use unique validator for email in my model, but it doesn't work.. i mean no notification that display in form when user input the same email that already saved in db and user still can click submit button(and page reloaded) eventhough…
chiper4
  • 303
  • 5
  • 18
1
2 3