代码之家  ›  专栏  ›  技术社区  ›  Martin SpruÅ¡anský

电子邮件输入未将电子邮件地址作为新闻稿订阅框中的有效输入

  •  0
  • Martin SpruÅ¡anský  · 技术社区  · 7 年前

    我在opencart网站上有新闻稿订阅输入,当我输入电子邮件并按订阅时,它会说“电子邮件无效!:即使是你也无效。”。

    我使用了这个主题,并没有改变订阅模块中的任何内容, 您可以向下滚动到页脚,并在此处检查其行为: http://demopavothemes.com/pav_woosa/demo2/

    我想不出是什么问题。

    <div class="<?php echo $prefix; ?> newsletter-v1" id="newsletter_<?php echo $position.$module;?>">
        <form id="formNewLestter" method="post" action="<?php echo $action; ?>" class="formNewLestter">
            <div class="panel panel-v1">
                <div class="panel-heading">
                    <h4 class="panel-title"><?php echo $objlang->get("entry_newsletter");?></h4>          
                </div>              
                <div class="panel-body">
                    <div class="input-group">
                        <input type="text" placeholder="Email Here ..." class="form-control email" <?php if(!isset($customer_email)): ?> <?php endif; ?> size="18" name="email">
                        <div class="input-group-btn pull-left">
                            <button type="submit" name="submitNewsletter" class="btn btn-primary icon-mail radius-6x"><?php echo $objlang->get("button_subscribe");?></button>
                        </div>
                    </div>
                    <input type="hidden" value="1" name="action">
                    <div class="valid space-top-10"></div>
                </div>
                    <?php if (!empty($social)): ?>
                         <?php  echo html_entity_decode( $social );?>
                   <?php endif ?>
            </div>
        </form>
    </div>
    
    <script type="text/javascript"><!--
    
        $( document ).ready(function() {
            var id = 'newsletter_<?php echo $position.$module;?>';
            $('#'+id+' .box-heading').bind('click', function(){
                $('#'+id).toggleClass('active');
            });
    
            $('#formNewLestter').on('submit', function() {
                var email = $('.inputNew').val();
                $(".success_inline, .warning_inline, .error").remove();
                if(!isValidEmailAddress(email)) {               
                $('.valid').html("<div class=\"error alert alert-danger\"><?php echo $objlang->get('valid_email'); ?><button type=\"button\" class=\"close\" data-dismiss=\"alert\">×</button></div></div>");
                $('.inputNew').focus();
                return false;
            }
            var url = "<?php echo $action; ?>";
            $.ajax({
                type: "post",
                url: url,
                data: $("#formNewLestter").serialize(),
                dataType: 'json',
                success: function(json)
                {
                    $(".success_inline, .warning_inline, .error").remove();
                    if (json['error']) {
                        $('.valid').html("<div class=\"warning_inline alert alert-danger\">"+json['error']+"<button type=\"button\" class=\"close\" data-dismiss=\"alert\">×</button></div>");
                    }
                    if (json['success']) {
                        $('.valid').html("<div class=\"success_inline alert alert-success\">"+json['success']+"<button type=\"button\" class=\"close\" data-dismiss=\"alert\">×</button></div>");
                    }
                }
            });
            return false;
        });
    });
    
    function isValidEmailAddress(emailAddress) {
        var pattern = new RegExp(/^(("[\w-\s]+")|([\w-]+(?:\.[\w-]+)*)|("[\w-\s]+")([\w-]+(?:\.[\w-]+)*))(@((?:[\w-]+\.)*\w[\w-]{0,66})\.([a-z]{2,6}(?:\.[a-z]{2})?)$)|(@\[?((25[0-5]\.|2[0-4][0-9]\.|1[0-9]{2}\.|[0-9]{1,2}\.))((25[0-5]|2[0-4][0-9]|1[0-9]{2}|[0-9]{1,2})\.){2}(25[0-5]|2[0-4][0-9]|1[0-9]{2}|[0-9]{1,2})\]?$)/i);
        return pattern.test(emailAddress);
    }
    --></script>
    
    1 回复  |  直到 7 年前
        1
  •  2
  •   chris85 Ferenc Kurucz    7 年前

    该行:

    $('.inputNew')
    

    正在查找名为 inputNew email .

    <input type="text" placeholder="Email Here ..." class="form-control email" <?php if(!isset($customer_email)): ?> <?php endif; ?> size="18" name="email">
                                                                        ^^^^^
    

    form-control 但这听起来并不独特。一 id 或者你可以用 name

    $('input[name="email"]')
    

    var email = $('.email').val();
    

    var email = $('input[name="email"]').val();
    

    你可以在这里了解更多, https://api.jquery.com/category/selectors/ .