I created two modals one to create a post and another one to create gallery inside another view and it work perfect but after I click submit my form keeps the data entered even if I refresh the page it’s still have the data entered, is it possible to clear form after submit
The Post form View code is
<?php
use yii\helpers\Html;
use yii\widgets\ActiveForm;
/* @var $this yii\web\View */
/* @var $ly_addPost app\models\Posts */
/* @var $form yii\widgets\ActiveForm */
?>
<div class="posts-form">
<?php $form = ActiveForm::begin(); ?>
<?= $form->field($ly_addPost, 'Post_title')->textInput(['maxlength' => true]) ?>
<?= $form->field($ly_addPost, 'Post_text')->textarea(['rows' => 6]) ?>
<?= $form->field($ly_addPost, 'Post_file')->textInput(['maxlength' => true]) ?>
<?= $form->field($ly_addPost, 'Permission_id')->dropdownList([$ly_addPost->Permission_id]);?>
<div class="form-group">
<?= Html::submitButton('Create' , ['class' => 'btn btn-primary']) ?>
</div>
<?php ActiveForm::end(); ?>
</div>
and the controller code is
public function actionView($id)
{
$ly_addPost = new Posts();
$ly_addGallery = new Galleries();
$ly_addPost->Channel_id = $id;
$ly_addGallery->Channel_id = $id;
$ly_addPost->Userid = Yii::$app->user->id;
$ly_addGallery->Userid = Yii::$app->user->id;
if ($ly_addPost->load(Yii::$app->request->post()) ) {
$ly_addPost->Post_id = Yii::$app->params['ly_randCttid'];
$ly_addPost->Post_uid = Yii::$app->params['ly_randCttuid'];
$ly_addPost->save();
foreach($ly_addPost as $property => $value) {
$value =null;
//var_dump ($value);
}
return $this->render('view', [
'model' => $this->findModel($id),
'ly_addPost' => $ly_addPost,
'ly_addGallery' => $ly_addGallery,
]);
exit();
} else {
return $this->render('view', [
'model' => $this->findModel($id),
'ly_addPost' => $ly_addPost,
'ly_addGallery' => $ly_addGallery,
]);
}
}
I used $value = null ;
and even so it’s not working