Search code examples
phpjqueryyiipjax

how can i avoid pjax to submit a form twice in yii?


Is there any way to stop user to send multiple submit to server by fast clicking on submit button when using pjax in yii ?

<?php 
  Pjax::begin()
  $form = ActiveForm::begin(['options' => ['data' => ['pjax' => true]],]); 

  echo $form->field($model, 'username');
  echo $form->field($model, 'password')->passwordInput();
  echo Html::submitButton(Yii::t('app', 'Submit'), ['class' => 'btn btn-primary']);

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

Solution

  • You need to disable the submit button after successfully submit( Without any remaining form validation error) so you can avoid multi submit at a time.