how to set succes message in model?

Hello,

is there a way to set success message for axaj validation in model?

Just like addError() sets the error message with the css class ‘errorMessage’.

Now I am setting success messages like this:

$this->addError(‘email’, ‘<span class=“success”>User with that email address already exist</span>’);

but this looks "ugly".

Thank you in advance.

see setFlash() and getFlash():

http://www.yiiframework.com/doc/api/1.1/CWebUser#setFlash-detail

http://www.yiiframework.com/doc/api/1.1/CWebUser#getFlash-detail

Hope this helps

Thanks, but that is not what I need. I’ll explain better.

I’ve created registration form with fields nickname, email etc.

Fields are validated when user clicks to next field and if, for instance,

user with same nickname exists addError() is triggered and displays error text right next to the field "User already exists".

What I need at that point is:

if user does not exist and nickaname is available, to show appropriate message

but I don’t want to use addError() method.

I hope that was clear enough :)

So you mean something like


$this->addError('email', '<span class="success">User is available</span>');

If it looks ugly, why don’t you style it (CSS) to fit your needs? You can style both this span (you add [color="#000080"][font=“Courier New”]div.form .errorMessage .success[/font][/color]) and the input field (you customize or override [color="#000080"][font=“Courier New”]div.form div.success input, div.form div.success textarea, div.form div.success select, div.form input.success, div.form textarea.success, div.form select.success[/font][/color] in form.css (line 109))

Edit : But it should prevent the form validation at all… So maybe you should just add your own method addSuccess?

See also: http://www.yiiframework.com/forum/index.php?/topic/24722-field-validated-display-success-message/

Yes

and didn’t mean ugly like that :)

I think it’s “ugly” to have method named addError to displays success messages, that’s all.

And it may be confusing for other developers.

Thank you for quick reply.