![](/img/trans.png)
[英]Prevent (non-bootstrap) Modal Popup from immediately closing after button submit, and display messages
[英]Prevent Bootstrap Model from Closing after Submit Button
我想防止在我按下“提交表單”按鈕后關閉“模態”窗口。
我嘗試了jquery / credform / javascript等不同的方式,但沒有任何結果給我我想要的結果。
如您所見,在我的模態中,我有一個包含不同內容的表單。 我的PHP服務器要求所有字段。
這個你能幫我嗎。 我希望在推送提交后保持打開狀態,以便完成表單的用戶在我在那里做的框中收到一條消息
$('#myModal').on('hidden.bs.modal', function() { this.modal('show'); });
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script> <div class="container"> <div id="myModal" class="modal hide fade" tabindex="-1" role="dialog" aria-labelledby="myModalLabel" aria-hidden="true"> <div class="modal-dialog"> <div class="modal-content"> <div class="modal-header"> <button type="button" class="close" data-dismiss="modal">×</button> <h4 class="modal-title">Comanda prin Email</h4> </div> <div class="modal-body"> <?php include('forms.php'); ?> <div class="container"> <form id="contact" action="<?= htmlspecialchars($_SERVER["PHP_SELF"]) ?>" method="post"> <div class=""><p style="text-align: center;">Dupa plasarea comenzi in maximum 24 ore ve-ti fi contactat Telefonic pentru confirmarea acesteia!!!</p></div> <fieldset> <sup>*</sup> <input placeholder="Nume Produs" type="text" name="numeprodus" value="<?= $numeprodus ?>" tabindex="1" autofocus> <span class="error"><?= $numeprodus_error ?></span> </fieldset> <fieldset> <sup>*</sup> <input placeholder="Marimea" type="text" name="marime" value="<?= $marime_produs ?>" tabindex="2" autofocus> <span class="error"><?= $marime_error ?></span> </fieldset> <fieldset> <sup>*</sup> <input placeholder="Numele" type="text" name="nume" value="<?= $nume ?>" tabindex="3" autofocus> <span class="error"><?= $nume_error ?></span> </fieldset> <fieldset> <sup>*</sup> <input placeholder="Prenumele" type="text" name="prenume" value="<?= $prenume ?>" tabindex="4" autofocus> <span class="error"><?= $prenume_error ?></span> </fieldset> <fieldset> <sup>*</sup> <input placeholder="Adresa" type="text" name="adresa" value="<?= $adresa ?>" tabindex="5" autofocus> <span class="error"><?= $adresa_error ?></span> </fieldset> <fieldset> <sup>*</sup> <input placeholder="Oras" type="text" name="oras" value="<?= $oras ?>" tabindex="6" autofocus> <span class="error"><?= $oras_error ?></span> </fieldset> <fieldset> <sup>*</sup> <input placeholder="Cod Postal" type="text" name="codpostal" value="<?= $codpostal ?>" tabindex="7" autofocus> <span class="error"><?= $codpostal_error ?></span> </fieldset> <fieldset> <sup>*</sup> <input placeholder="Email" type="text" name="email" value="<?= $email ?>" tabindex="8"> <span class="error"><?= $email_error ?></span> </fieldset> <fieldset> <sup>*</sup> <input placeholder="Numar Telefon" type="text" name="telefon" value="<?= $telefon ?>" tabindex="9"> <span class="error"><?= $telefon_error ?></span> </fieldset> <fieldset> <textarea value="<?= $message ?>" name="message" tabindex="10"> </textarea> </fieldset> <fieldset> <button name="submit" type="submit" id="contact-submit" data-submit="...Sending">Submit</button> </fieldset> <div class="success"><?= $success ?></div> </form> </div> </div> <div class="dv-atentionare"><p class="dv-att-p1">Atentie!</p><p class="dv-att-p2">Aveti la dispozitie 48 ore de la plasarea comenzi pentru ao putea anula!</p></div> <div class="modal-footer"> <input class="btn btn-default"> <button type="button" class="btn btn-default" data-dismiss="modal">Close</button> </div> </div> </div> </div> </div>
先感謝您!
好的,因此有兩種解決方案。
使用JQuery AJAX提交表單,並防止默認表單行為。 鏈接
從服務器返回表單時,請重新打開模式。 我可能無法為此提供任何PHP
代碼,但是我已經在Asp.Net MVC.
完成了此操作Asp.Net MVC.
將數據發布到PHP
,從那里返回一些標志。 然后,您可以使用該標志打開/關閉以下腳本。
// PHP if($some_flag == true)
<script>
$(document).ready(function(){
$('#myModal').modal('show');
})
</script>
// PHP endif
根據文檔, data-dismiss="modal"
是在單擊按鈕時關閉模態。
單擊該按鈕后,刪除此屬性將阻止模式關閉。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.