Validators extending from CValidator all have a property named message. You can set this property in the corresponding validation rule to customize the error message. For example, the following validation rule uses an error message that is different from the default one:
class Post extends CActiveRecord { public function rules() { return array( array('title, content', 'required', 'message'=>'Please enter a value for {attribute}.'), // ... other rules ); } }
In the above, the customized error message contains a predefined placeholder {attribute}. The CRequiredValidator (whose alias is required) will replace this placeholder with the actual attribute name that fails the validation.
Total 3 comments
Here's a list of many placeholders and the validators that are using them:
Of course, {attribute} is known in all validators. So, which placeholders are known depends on the validator and the condition as well: By default {min} is only used when the value is below the min value (as defined in rules) and {max} when the value is above the max value.
No, you SHOULD use {attribute} placeholder. Look for predefined {attribute} placeholder.
What about the value of the attribute? That is in default error messages. Shouldn't there be a {value} ?
Leave a comment
Please login to leave your comment.