I’m trying to display a success message, if there are no validation errors for each model attribute.
In Short: Display a Success Message instead of an error Message, the same way there is addError, i want addMessage but it would allow the form to submit. I’ve been trying to do it via flashes, but its not working and It won’t work via ajax.
Here I’m just trying to test it for the firstName attribute in my model/form
if(!$model->hasErrors(‘firstName’)) {
Yii::app()->user->setFlash('success','First name looks great!');
}
Except that its always doing it, when the page reloads…simply because it has no errors when the page is loaded.
I wanted it to check if it has passed its validated state, then display the message.
Well you can use onAfterValidate and check whether they are no errors or not and setFlash with content that you will after display extracting the messages from it.
However is there anyway to do it via like addError, instead its like addMessage. If I add an error, the page won’t validate and save. Flashes won’t work on ajax forms. They will only work if I refresh the form or something.