Answer the question
In order to leave comments, you need to log in
Why does the button in yii2 work only on the second click?
The View has a button:
<?php $newForm = ActiveForm::begin(); ?>
<div class="form-group">
<?= Html::submitButton('Clear',['class'=>'btn btn-danger', 'name' => 'submit', 'value' => 'clear_unique_users_table']) ?>
</div>
<?php ActiveForm::end(); ?>
if(Yii::$app->request->post('submit')==='clear_unique_users_table'){
if($uniqueUsersModel->clearTable()){
return $this->refresh();
}
}
Answer the question
In order to leave comments, you need to log in
You need to look for js that intercepts the click on the button. Apparently you wrote somewhere a click handler with a very general selector, like:
$('button').on('click',finction(e){
e.preventDefault();
//some code
});
Hello.
--
To mine a problem in double conditions, two if are strange. I faced a similar situation. You just need to write:
public function actionCleartable()
{
$ok = Yii::$app->request->post('submit');
if(isset($ok)) {
$uniqueUsersModel->clearTable();
return $this->refresh();
} else {
return $this->render('cleartable');
}
}
<?= Html::beginForm(['order/update', 'id' => $id], 'post', ['enctype' => 'multipart/form-data']) ?>
<?= Html::submitButton('Отправить', ['class' => 'submit', 'name' => 'submit']) ?>
<?= Html::endForm() ?>
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question