简体   繁体   English

当我在jquery的订阅表单中输入重复的无效电子邮件或空白条目时设置错误按钮

[英]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.

相关问题 如果电子邮件输入处于焦点位置,则阻止输入按钮表单提交(jquery) - Prevent enter button form submission if email input is on focus (jquery) 如果我在javascript中输入无效的电子邮件或空白,如何显示特定的文本框边框红色? - How to show particular textbox border red color if i enter invalid email or blank in javascript? 当我有按钮而不是提交时如何使用回车键提交表单 - How to submit form with enter key when I have a button, not a submit 自定义 web 可访问性错误消息,当按下提交按钮上的键盘输入并且输入字段为空白时 - custom web accessibility error message when pressed enter with keyboard on submit button and input field is blank 当用户使用jquery输入无效的日期或月份时,下一步按钮将被禁用 - Next button will be disabled when user enter invalid date or month using jquery jQuery错误,检查是否为空白表格 - jquery error with check if blank form 当用户单击按钮时输入无效的日期格式时,如何显示验证错误? - how to show validation error when user enter invalid date format on button click? 当以非形式按“输入”时,按钮隐藏且可单击 - Button Hidden and clickable when press “enter” in not a form 按回车键提交表格,不按按钮 - Submit form when press enter, not press button 单击“ Enter”按钮时提交表单,并进行验证 - Submit form when Clicking “Enter” button, with validation
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM