如何解决在模态php中显示表单错误消息
我有几条错误消息要显示,在检查表单时,我想以引导方式显示它们。
我当时正在考虑使用会话,但是我不知道出现错误时如何触发模式。我应该使用js还是jQuery?如果您有更好的方式来美观地处理错误消息,请提前...
以下是我的代码的摘录:
PHP部分
// Clean retrieved client data
$client = dataCleaning($_POST['client']);
// Check if the client name is at least 2 characters
if(mb_strlen($client) < 2 ){
// echo'Le nom du client doit comporter au moins 2 caractères';
$_SESSION['error'] = 'Le fichier doit être une image png ou jpg';
header('Location: test.php');
die;
}
HTML部分
if(isset($errors) && !empty($errors)):?>
<div class="modal fade" style="background-color: #e64827" id="errorModal" tabindex="-1" role="dialog" data-backdrop="static" data-show="true">
<div class="modal-dialog modal-dialog-centered" role="document">
<div class="modal-content">
<div class="modal-header">
<h5 class="modal-title font-weight-bold text-uppercase" id="errorModalLabel">
<i class="fas fa-exclamation-circle" style="color: #e64827"></i>
Erreur
</h5>
<button type="button" class="close" data-dismiss="modal" aria-label="Close">
<span aria-hidden="true">×</span>
</button>
</div>
<?php foreach($errors as $error):?>
<div class="modal-body font-weight-bold" id="error_message">
<?=$error;?>
<?php endforeach;?>
<div class="modal-footer">
<a href="<?= $_SERVER['HTTP_REFERER'] ?>"><button type="button" class="btn btn-secondary">Retour</button></a>
</div>
</div>
</div>
</div>
<?php endif;?>
版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。