poll.php 897 B

12345678910111213141516171819202122232425262728293031323334353637
  1. <?php
  2. use yii\helpers\Html;
  3. use yii\helpers\Url;
  4. use app\models\Inquirer;
  5. use yii\web\View;
  6. if( $model->active == 'Y' && $model->show == 'Y' ){
  7. $answers = $model->getAnswers();
  8. foreach($answers as $item){
  9. ?>
  10. <div class="form-check">
  11. <input class="form-check-input" type="radio" id="Radio<?=$item->id?>" name="ask" value="<?=$item->id?>">
  12. <label class="form-check-label" for="Radio<?=$item->id?>">
  13. <?=$item->text?>
  14. </label>
  15. </div>
  16. <?
  17. }
  18. }
  19. ?>
  20. <button class="btn btn-primary mt-4" onclick="sendask()">Голосовать</button>
  21. <?
  22. $filterurl = \yii\helpers\Url::base('https')."/inquirer/ajax";
  23. $this->registerJs(
  24. <<<JS
  25. function sendask(){
  26. ask = $('input:checked[name=ask]').val()
  27. $.post( "$filterurl", { 'idq': $model->id, 'ask': ask }, function( data ) {
  28. if( data.status == 'ok' ){
  29. document.location.reload();
  30. }
  31. });
  32. }
  33. JS
  34. ,
  35. View::POS_END
  36. );