PHPackages                             w3lifer/yii2-ajax-active-form - PHPackages - PHPackages  [Skip to content](#main-content)[PHPackages](/)[Directory](/)[Categories](/categories)[Trending](/trending)[Leaderboard](/leaderboard)[Changelog](/changelog)[Analyze](/analyze)[Collections](/collections)[Log in](/login)[Sign up](/register)

1. [Directory](/)
2. /
3. [Templating &amp; Views](/categories/templating)
4. /
5. w3lifer/yii2-ajax-active-form

ActiveYii2-extension[Templating &amp; Views](/categories/templating)

w3lifer/yii2-ajax-active-form
=============================

1.0.0(8y ago)017MITPHP

Since Apr 26Pushed 1y ago1 watchersCompare

[ Source](https://github.com/w3roman/yii2-ajax-active-form)[ Packagist](https://packagist.org/packages/w3lifer/yii2-ajax-active-form)[ RSS](/packages/w3lifer-yii2-ajax-active-form/feed)WikiDiscussions master Synced yesterday

READMEChangelogDependencies (1)Versions (2)Used By (0)

yii2-ajax-active-form
=====================

[](#yii2-ajax-active-form)

- [Installation](#installation)
- [Usage](#usage)

Installation
------------

[](#installation)

```
composer require w3lifer/yii2-ajax-active-form
```

Usage
-----

[](#usage)

- Action:

```
/**
 * @return mixed
 * @throws \yii\base\InvalidConfigException
 * @throws \yii\web\BadRequestHttpException
 * @see https://github.com/w3lifer/response-interface
 * @see https://github.com/w3lifer/php-helper
 */
public function actionIndex()
{
    $model = new AjaxActiveFormModel();
    if (Yii::$app->request->isPost) {
        Yii::$app->response->format = Response::FORMAT_JSON;
        if ($model->load(Yii::$app->request->post()) && $model->save()) {
            return ResponseInterface::getTrueResponse();
        } else if ($model->errors) {
            $lowerCasedFormName = strtolower($model->formName());
            $errors =
                PhpHelper::add_prefix_to_array_keys(
                    $model->errors,
                    $lowerCasedFormName . '-',
                    false
                );
            return ResponseInterface::getFalseResponse($errors);
        }
        throw new BadRequestHttpException();
    }
    return $this->render('index', compact('model'));
}
```

- View:

```
