【发布时间】:2018-01-08 19:12:41
【问题描述】:
我有一个表单,它在 PHP 中服务器端处理开始之前使用 javascript onSubmit 使用非常基本的输入验证。
但是,由于 PHP 脚本处理(上传图像等)所花费的时间,我尝试使用相同的 onSubmit 函数在通过验证时显示“请稍候”通知。或者,还有更好的方法?我在 PHP 中尝试过,但必须先完成处理,然后才能回显任何输出。我从其他 SO 帖子中尝试过的任何内容都会停止验证过程。
<form id="form" method="post" action="" onsubmit="return Validate(this)" autocomplete="off">
当前的 Javascript 示例
function Validate(myForm) {
var error = '';
// Example Filed
if(myForm.name.value == '') {
error += '- Please enter your Name.\n';
}
// Show Error Notice
if(error != '') {
error = 'The form has not been completed correctly, please check the following:\n\n' + error;
alert(error); // Displays Error
return false;
} else {
// Allows the form to move on to PHP Processing
// Need to Show Waiting Notice here
return true;
}
}
CSS & HTML 等待通知(最初隐藏)
<style>
#processing {
display:block;
position: fixed;
top: 0;
left: 0;
background: rgba(255,255,255,0.8);
width: 100%;
height: 100%;
}
#popup {
width: 300px;
min-height: 160px;
padding:20px;
background-color: #fff;
border: 5px solid #06C;
text-align: center;
color: #202020;
position: absolute;
left: 50%;
top: 50%;
margin-left: -150px;
margin-top: -100px;
-webkit-border-radius: 15px;
-moz-border-radius: 15px;
border-radius: 15px;
}
#popup img {
height:60px;
width:60px;
}
</style>
<div id="processing">
<div id="popup">
<img width="60" height="60" src="../waiting.gif" />
<h3>Please Wait!</h3>
<p>The form is processing...</p>
</div>
</div>
任何帮助将不胜感激
【问题讨论】:
标签: javascript php jquery validation onsubmit