简体   繁体   English

jQuery验证插件onclick链接

[英]JQuery validation plugin onclick link

I have a form that uses a link to submit the results. 我有一个使用链接提交结果的表格。 I'm using Jquery validation plugin. 我正在使用Jquery验证插件。

I can get the form to validate if I use a normal button to submit the form. 如果我使用普通按钮提交表单,则可以验证表单。 How can I call the Jquery function from a hyperlink instead of a button. 如何从超链接而不是按钮调用Jquery函数。 Here's my jquery: 这是我的jQuery:

<script type="text/javascript">
     $(document).ready(function () {
        $('#newsletter_form').validate({ 
            rules: {
                CONTACTS_EMAIL: {
                    required: true,
                    email: true
                },
                CONTACTS_PRIVACY_POLICY_AGREE: "required",
            },
            messages: {
                CONTACTS_PRIVACY_POLICY_AGREE: "<?php echo $FRM_ERRMSG_CONTACTS_PRIVACY_POLICY_AGREE;?>",
                CONTACTS_EMAIL: {
                  required: "<?php echo $FRM_ERRMSG_CONTACTS_EMAIL;?>",
                  email: "<?php echo $FRM_ERRMSG_CONTACTS_EMAIL_FORMAT;?>"
                }
              },
            submitHandler: function (form) { 
                form.submit();
            }
        });   
    });
 </script>

And here is my html (with some php inside to be ignored) 这是我的html(里面有一些php被忽略)

<form id="newsletter_form" name="newsletter_form" action="newsletter_submit.php" method="post" >
        <br>
        <div class="mc-field-group">
            <input type="text" name="CONTACTS_EMAIL" placeholder="*<?echo $EMAIL_FIELD_TEXT;?>" style="width: 280px;font-size: 20px;" /><br>
            <input type="checkbox" name="CONTACTS_PRIVACY_POLICY_AGREE"> <?echo $PRIVACY_POLICY;?> * <label for="CONTACTS_PRIVACY_POLICY_AGREE" class="error" style="display:none;"></label>

            <input type="hidden" name="CONTACTS_LANGUAGE" value="<?echo $language;?>">
            <div>
                <input type='submit' style='position:absolute;top:0;left:-9999px;width:1px;height:1px' name='newsletter_form'>
                <a style="margin-top:22px;" class="wsite-button external-link" onclick="document.getElementById('newsletter_form').submit()"> 
                <span class="wsite-button-inner"><?echo $BUTTON_TEXT;?></span></a>
            </div>
        </div>
    </form>

Try using jQuery to trigger the submit event: 尝试使用jQuery触发Submit事件:

onclick="$('#commentForm').submit();"

There's a lot that could be improved here, but that may fix your core problem. 这里有很多可以改进的地方,但是可以解决您的核心问题。 I remember something like this happening to me a long time ago. 我记得很久以前就发生过这样的事情。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM