每當我單擊它時,我的提交按鈕的模態都不會彈出(它會彈出,但只是一瞬間)。連接到提交按鈕的模式的目的是確保用戶不會在表單中有未填充欄位時重定向到下一頁(通過使用驗證規則)。我正在使用引導程式、codeigniter4 和 php。有人能幫我嗎?
這是模態的代碼:
<?php if (isset($validation)) :?>
<div class="modal" id="exampleModal" tabindex="-1" aria-labelledby="exampleModalLabel" aria-hidden="true">
<div class="modal-dialog modal-dialog-centered">
<div class="modal-content">
<div class="modal-header">
<h5 class="modal-title" id="exampleModalLabel">The following fields are required </h5>
<button type="button" class="btn-close" data-bs-dismiss="modal" aria-label="Close"></button>
</div>
<div class="modal-body">
<div class="text-danger">
<?= $validation->listErrors()?>
</div>
</div>
<div class="modal-footer">
<button type="button" class="btn btn-secondary" data-bs-dismiss="modal">Close</button>
</div>
</div>
</div>
</div>
<?php endif;?>
這是按鈕的代碼:
<button type="submit"class="btn btn-primary me-2" id="submit" data-bs-toggle="modal" data-bs-target="#exampleModal">Submit</button>
任何幫助將不勝感激,謝謝!
uj5u.com熱心網友回復:
據我了解,如果用戶沒有填寫所有詳細資訊,您想彈出模型。實作這一點的最簡單方法是首先檢查是否存在任何驗證錯誤。就像是:
<?php if($validation_errors){ ?>
<button type="button"class="btn btn-primary me-2" id="submit" data-bs-toggle="modal" data-bs-target="#exampleModal">Submit</button>
<?php }else{ ?>
<button type="submit"class="btn btn-primary me-2" id="submit">Submit</button>
<?php } ?>
更方便的是使用引導警報。
轉載請註明出處,本文鏈接:https://www.uj5u.com/gongcheng/445964.html
上一篇:錯誤:不允許執行您請求的操作。當CodeIgniter4中的HTTP請求方法為“POST”時,我的API被過濾器阻止
下一篇:撰寫CSV檔案換行符顯示為文本
