[英]Set error button when i enter repeated invalid email or blank entry in subscribe form in jquery
I have been created subscribe form using php and jquery and sql to store data. 我已经使用php和jquery和sql创建了订阅表单来存储数据。
Now it is working fine, but it has some limitation. 现在它可以正常工作,但是有一些限制。
When i enter invalid email address, it shows like this, 当我输入无效的电子邮件地址时,它显示如下:
But i need to remove that message, i need only working effects with error button. 但是我需要删除该消息,我只需要带有错误按钮的工作效果即可。
And If i enter blank, that time error button working fine[that is button will be shaken and says error], after that i enter valid address, it also working fine[that is success button]. 如果我输入空白,则该时间错误按钮可以正常工作(即按钮将被震动并显示错误),之后我输入有效地址,它也可以正常工作(即成功按钮)。
One more think, if i enter invalid address at first, and second also enter invalid address,, the error button works fine at first time only. 再想一想,如果我首先输入无效的地址,然后又输入无效的地址,则错误按钮仅在第一次有效。
Here is lib.js: 这是lib.js:
$(document).ready(function () {
$('#newsletter').submit(function () {
var $this = $(this),
$response = $('#response'),
$mail = $('#signup-email'),
testmail = /^[^0-9][A-z0-9._%+-]+([.][A-z0-9_]+)*[@][A-z0-9_]+([.][A-z0-9_]+)*[.][A-z]{2,4}$/,
hasError = false;
$response.find('p').remove();
if (!testmail.test($mail.val())) {
$('#actbtn').removeClass('btn-error').addClass('btn-error');
//$response.html('<p class="error">Please enter a valid email</p>');
hasError = true;
}
if (hasError === false) {
$response.find('p').remove();
$response.addClass('loading');
$.ajax({
type: "POST",
dataType: 'json',
cache: false,
url: $this.attr('action'),
data: $this.serialize(),
success: function(data){
if(data!=''){
$response.removeClass('loading');
if(data.status == 'success'){
$('#actbtn').removeClass('btn-error').addClass('btn-success');
}
else{
$('#actbtn').removeClass('btn-error').addClass('btn-error');
}
}
}
});
}
return false;
});
});
html: HTML:
<div id="newsletterform">
<div class="wrap">
<h3>Get Email Update</h3>
<form action="send.php" method="post" id="newsletter" name="newsletter">
<input type="email" name="signup-email" id="signup-email" value="" placeholder="Insert email here" />
<button id="actbtn" class="btn btn-7 btn-7h icon-envelope">Submit form</button>
<span class="arrow"></span>
</form>
<div id="response"></div>
</div>
</div>
May i know,how to achieve this one, Any idea would be highly appreciated. 我想知道,如何实现这一目标,任何想法将不胜感激。
Thanks in advance. 提前致谢。
You have used the 您已经使用了
<input type="email" name="signup-email" id="signup-email" value="" placeholder="Insert email here" />
try to use it as input text because you did the script validation 尝试将其用作输入文本,因为您执行了脚本验证
<input type="text" name="signup-email" id="signup-email" value="" placeholder="Insert email here" />
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.