Title: Validate Yii2 Activeform on simple button click
Tags: php;yii2;yii2-basic-app;yii2-validation
Question: I want to validate my Yii2 activeform on simple button click which is not submitButton. I tried ```$('#formId').yiiActiveForm("validate")``` but it is not working.

I also tried - ```$('#formId').yiiActiveForm('submitForm')``` it validates form but it also submit it if everything is ok. I don't want to submit that form. I just want to validate it on button click and if everything is ok than i want to open a modal popup.

What are possible ways to validate this activeform on button click


Here is the accepted answer: To validate your form perform ajax validation only inside your action as follows. This will only validate your form

```public function actionValidateForm() {
        $model = new Form();

        if (Yii181a:6c1c:918f:f3a4:2e8c:61d6:1a08:6b16$app-&gt;request-&gt;isAjax &amp;&amp; $model-&gt;load(Yii181a:6c1c:918f:f3a4:2e8c:61d6:1a08:6b16$app-&gt;request-&gt;post())) {
            Yii181a:6c1c:918f:f3a4:2e8c:61d6:1a08:6b16$app-&gt;response-&gt;format = Respons181a:6c1c:918f:f3a4:2e8c:61d6:1a08:6b16FORMAT_JSON;
            return ActiveForm181a:6c1c:918f:f3a4:2e8c:61d6:1a08:6b16validate($model);
            Yii181a:6c1c:918f:f3a4:2e8c:61d6:1a08:6b16$app-&gt;end();
        }
    }
```

Comment for this answer: Thanks Nitin. Almost done can u suggest one more thing. It is not removing error class from field. even after entring correct data. Validation is working fine just error message is not getting removed
Comment for this answer: I tried validateOnChange and validateOnBlur but error message is still displaying.
Comment for this answer: it is set to value true
Comment for this answer: you need to set form properties like

`enableAjaxValidation,enableClientValidation,validateOnChange,validateOnSubmit` to `true`
Comment for this answer: what about `enableAjaxValidation` ? is it set to true

Here is another answer: You have to set ```enableClientValidation = false,``` in you'r form's options .


{'source': 'StackExchangeDataset', 'subset': 'stackoverflow.com', 'metadata': {'AnswerCount': 2, 'CommentCount': 0, 'ContentLicense': 'CC BY-SA 3.0', 'CreationDate': '2016:00:10/26/16', 'FavoriteCount': None, 'PostTypeId': 1, 'Tags': '<php><yii2><yii2-basic-app><yii2-validation>', 'Title': 'Validate Yii2 Activeform on simple button click', 'ViewCount': 1180, 'id': 40254126, 'user_AboutMe': '<p>I am a passionate programmer with 7 years of experience in the web development field. I like to learn new things and always ready to take challenges to achieve desired goals. I have experience of working in. PHP, Yii2, Javascript, NodeJs, Angular, and Mysql.</p>\n', 'user_AccountId': 3239439.0, 'user_DisplayName': 'Ninja Turtle', 'user_Reputation': 1213.0, 'user_Views': 152.0, 'user_id': 7840227.0}}