使用 Spry 验证的 ajaxForm

发布于 2024-11-24 01:53:57 字数 596 浏览 1 评论 0原文

我正在尝试将 spry 验证与 ajaxForm 一起使用。问题是我不认为我在 beforeSubmit 时强制进行 spry 验证是找到表单。我没有收到任何错误,似乎 beforeSubmit 没有触发,因为它找不到表单“form1”

$("#form1").ajaxForm({
        url: "processPhoneEdit.php",
        beforeSubmit: function(){
            if (Spry) { // checks if Spry is used in your page
                var r = Spry.Widget.Form.validate(form1); // validates the form
                    if (r) 
                        alert("testing");
                        return (r);

            } 
        },
        success: alert("success"),
        complete: alert("complete")
});

I am trying to use spry validation with ajaxForm. The problem is I don't think my forcing spry validation at time of beforeSubmit is finding the form. I'm not getting any errors, seems like beforeSubmit isn't firing because it can't find the form, "form1"

$("#form1").ajaxForm({
        url: "processPhoneEdit.php",
        beforeSubmit: function(){
            if (Spry) { // checks if Spry is used in your page
                var r = Spry.Widget.Form.validate(form1); // validates the form
                    if (r) 
                        alert("testing");
                        return (r);

            } 
        },
        success: alert("success"),
        complete: alert("complete")
});

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

ゝ偶尔ゞ 2024-12-01 01:53:57

我不是一个程序员,但这是我的解决方案:

    // Submit button is clicked
    $("#submitShipment").click(function () 
    {

        // Spry validation:  if true
        if (Spry.Widget.Form.validate(form1) == true)
            {

                // opens the Please Wait dialog
                $('#dialogPleaseWait').dialog('open');
                // disables the submit button
                $('#submitShipment').button('disable');
                // Posts form to callback page, serializes the form into a URL string and waits for a result (success / fail)
                $.get("callbacks/insertShipment.asp", $("#form1").serialize(), insertCallback);

            } 
            else  // Spry validation:  if false
            {
                // opens jQuery UI dialog to inform user Validation failed
                $('#dialogDespatchValFail').dialog('open');
            }

    });

I'm not much of a programmer, but this was my solution:

    // Submit button is clicked
    $("#submitShipment").click(function () 
    {

        // Spry validation:  if true
        if (Spry.Widget.Form.validate(form1) == true)
            {

                // opens the Please Wait dialog
                $('#dialogPleaseWait').dialog('open');
                // disables the submit button
                $('#submitShipment').button('disable');
                // Posts form to callback page, serializes the form into a URL string and waits for a result (success / fail)
                $.get("callbacks/insertShipment.asp", $("#form1").serialize(), insertCallback);

            } 
            else  // Spry validation:  if false
            {
                // opens jQuery UI dialog to inform user Validation failed
                $('#dialogDespatchValFail').dialog('open');
            }

    });
转瞬即逝 2024-12-01 01:53:57

试试这个..

$("#form1").ajaxForm({
            target:'#some_div',
            url:'processPhoneEdit.php',
            clearForm: 'true',
            beforeSubmit: function(formData, jqForm, options){
            if (Spry) { // checks if Spry is used in your page
                r = Spry.Widget.Form.validate(jqForm[0]); // validates the form
                if (!r) {
                    return r;
                }
            }
            if(r)   {
                $('#submit').attr({
                    'disabled':'disabled',
                    'value':'Processing. Please Wait...'
                });     
            }
            },
            success: function() {
                $('#form1').hide();
            } 
        });

Try this..

$("#form1").ajaxForm({
            target:'#some_div',
            url:'processPhoneEdit.php',
            clearForm: 'true',
            beforeSubmit: function(formData, jqForm, options){
            if (Spry) { // checks if Spry is used in your page
                r = Spry.Widget.Form.validate(jqForm[0]); // validates the form
                if (!r) {
                    return r;
                }
            }
            if(r)   {
                $('#submit').attr({
                    'disabled':'disabled',
                    'value':'Processing. Please Wait...'
                });     
            }
            },
            success: function() {
                $('#form1').hide();
            } 
        });
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文