PHP code example of w3lifer / yii2-ajax-active-form
1. Go to this page and download the library: Download w3lifer/yii2-ajax-active-form library. Choose the download type require.
2. Extract the ZIP file and open the index.php.
3. Add this code to the index.php.
<?php
require_once('vendor/autoload.php');
/* Start to develop here. Best regards https://php-download.com/ */
w3lifer / yii2-ajax-active-form example snippets
php
/**
* @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'));
}