модальное_окно

Различия

Показаны различия между двумя версиями страницы.

Ссылка на это сравнение

Предыдущая версия справа и слева Предыдущая версия
Следующая версия
Предыдущая версия
модальное_окно [2022/01/19 08:45] adminмодальное_окно [2022/02/11 17:55] (текущий) – внешнее изменение 127.0.0.1
Строка 8: Строка 8:
   <div class="modal-dialog">   <div class="modal-dialog">
     <div class="modal-content">     <div class="modal-content">
-      <div class="modal-body"><img src="preload.gif"></div>+        <div style="margin:auto"> 
 +            <img class="img" src="<?= Url::to(['/img/preload.gif'])?>"> 
 +        </div>
     </div>     </div>
   </div>   </div>
Строка 15: Строка 17:
  
 <code | Yii2 js> <code | Yii2 js>
 +<?php
 $this->registerJs(" $this->registerJs("
-    $(document).on('click', '.js_openWindowModal', function () { +    $(document).on('click', '.js_openWindowModal', function (event) { 
-            $('#windowModal').modal('show').find('.modal-body').load($(this).href);+        event.preventDefault(); 
 +        $('#windowModal').modal('show').find('.modal-content').load($(this).attr('href'));
     });     });
 "); ");
Строка 60: Строка 64:
     }     }
 } }
 +</code>
 +
 +<code | Yii2 view>
 +
 +use yii\bootstrap4\ActiveForm;
 +
 +<?php $form = ActiveForm::begin(['id' => 'callme-form','options'=>['class'=>'js_modalForm']]); ?>
 +
 +      <div class="modal-header">
 +        <h5 class="modal-title" id="windowModalLabel">Modal title</h5>
 +        <button type="button" class="close" data-dismiss="modal" aria-label="Close">
 +          <span aria-hidden="true">&times;</span>
 +        </button>
 +      </div>
 +
 +      <div class="modal-body">
 + 
 +        <?= $form->field($model, 'name')->textInput(['autofocus' => true]) ?>
 +        <?= $form->field($model, 'email') ?>
 +        <?= $form->field($model, 'subject') ?>
 +        <?= $form->field($model, 'body')->textarea(['rows' => 6]) ?>
 +        <?= $form->field($model, 'verifyCode')->widget(Captcha::className(), [
 +            'template' => '<div class="row"><div class="col-lg-3">{image}</div><div class="col-lg-6">{input}</div></div>',
 +            ]) ?>
 +   </div>
 +    <div class="modal-footer">
 +        <button type="button" class="btn btn-default" data-dismiss="modal">Close</button>
 +        <?= Html::submitButton('Submit', ['class' => 'btn btn-primary', 'name' => 'contact-button']) ?>
 +    </div>
 + 
 +<?php ActiveForm::end(); ?>
 +</code>
 +<code | Yii2 JS для формы>
 +<?php
 +$this->registerJS("
 +    $(document).on('beforeSubmit', '.js_modalForm', function (event) {
 +    
 +            event.preventDefault();
 +
 +            var form = $(this);
 +
 +            $.ajax({
 +                   url: form.attr('action'), 
 +                   cache: false,
 +                   contentType: false,
 +                   processData: false,
 +                   data: form.serialize(),
 +                   type: 'post',
 +                   beforeSend: function() {
 +                   },
 +                   success: function(response){
 +                       toastr.success('',response.message);
 +                       $('#windowModal').modal('hide');
 +                   },
 +                   complete: function() {
 +                   },
 +                   error: function (data) {
 +                      toastr.warning('','There may a error on uploading. Try again later');
 +                   }
 +                });                
 +            return false;
 +
 +    });
 +");
 +
 +?>
 </code> </code>
  • модальное_окно.1642581934.txt.gz
  • Последнее изменение: 2022/01/19 10:45
  • (внешнее изменение)