简体   繁体   English

SubmitHandler-jQuery验证和Magento

[英]submitHandler - Jquery Validate and Magento

For some reason I cannot get this to submit at all in magento. 由于某种原因,我无法在magento中完全提交此文件。 The form validates just fine. 该表格可以验证。 Its just it seems like once its validated it doesnt want to do anything. 它只是好像它一旦通过验证就不想做任何事情。

    $j('#send').click(function(){
    var form = $j('#share_email_submit');
    form.validate({
        submitHandler: function(){
            var data = $j(form).serialize();
            alert(data);
            $j.post('catdog.php', data);
        }
    }).form();
});

Any ideas? 有任何想法吗?

You can try to use the validate method of the validator magento object. 您可以尝试使用验证器magento对象的validate方法。

validator.validate() validateator.validate()

It returns boolean false if magento validation failed otherwise true. 如果magento验证失败,则返回boolean false,否则返回true。

To activate the magento validation, you should have set somewhere in your code something as 要激活magento验证,您应该在代码中的某处设置为

var validate_form = new VarienForm('form_id',true); var validate_form = new VarienForm('form_id',true);

It seems that in your code ' share_email_submit ' should be the above ' form_id ' 在您的代码“ share_email_submit ”中,似乎应该是上面的“ form_id

Then you can turn the code you posted into something like 然后,您可以将发布的代码变成类似

$j('#send').click(function()
{
    if (validate_form.validator.validate())
    {
        var form = $j('#share_email_submit');
        var data = $j(form).serialize();
        console.log(data);
        $j.post('catdog.php', data);
    }
    else
    {
        console.log('Validation Failed');
    }
    return false;
});

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

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