Active form Pjax Submit issue

Hi, i am trying to create a follow system to users. I created crud and it works ok. Now i am trying to add a follow button to user profile with pjax but it gives internal server error.

Here is code i added to profile page :

<?php Pjax::begin(['id' => 'ff']) ?>

<?php $form = ActiveForm::begin(['id'=>'fform', 'action' =>['follow/addfollow'],'options' => ['data' => ['pjax' => 1]]]); ?>

    <?= $form->field($model, 'uid')->hiddenInput(['value'=>$model->id])->label(false); ?>
   
    <div class="form-group">
            <?= Html::submitButton(Yii::t('app', 'Follow'), ['class' => 'btn btn-success']) ?>
    </div>

<?php ActiveForm::end(); ?>
<?php Pjax::end() ?>

FollowController php:

public function actionAddfollow() {
    $model = new Follow();

    $model->load(Yii::$app->request->post();
    $model->save();


    return $this->renderAjax('create', [
            'model' => $model,
        ]);
}

Hi There,

public function actionAddfollow() {
    $model = new Follow();
    $model->load(Yii::$app->request->post()); //Typo
    $model->save();

    return $this->renderAjax('create', [
                'model' => $model,
    ]);
}

Looks like typo, brocket missing

Nope, it is not bracket, i solved it but thanks for reply anyway.

The problem is user form, follow model conflict. I created active form in user view.php, so it created a form which uses user ids for fileds (not follow ids). But in controller.php i tried to load these user ided fields to follow model so it gives the error. For example the iput id must be “follow-followid” but active form created “user-followid” automatically.

I customized the submit form as follow form and now it works.

Now i have a new question. I did not use JSON for return data, because it returns only string and i want to return html tags in container which reloads with this cod $.pjax.reload({container:"#follows"});


public function actionAddfollow() {
	//Yii::$app->response->format = Response::FORMAT_JSON;
    $model = new Follow();

    $model->load(Yii::$app->request->post());
    $model->fid =Yii::$app->user->identity->id;

    
    if (!Follow::findOne(['fid' => $model->fid,'uid' => $model->uid,])){
    if ($model->save()) {
         return '<i class="fa-check-circle"></i> Following';
        }else {
        	return '<i class="fa-times-circle"></i> Failed';
      }
      }
      
}

is it cause any security issues or it is ok?

Thanks…