在提交Zend的形式AJAX验证 [英] Zend form ajax validation on submit

查看:117
本文介绍了在提交Zend的形式AJAX验证的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我目前正在验证使用Ajax和Zend Zend的形式验证的同时...

让我解释一下,我的形式弹出在iframe中(的fancybox),并提交时,我需要显示一个谢谢消息,关闭IFRAME和重定向用户。我计划用AJAX验证关闭的fancybox iframe中,如果成功。

我跟几个教程 HTTP:// WWW .zendcasts.com / ajaxify-您-Zend_Form的验证与 - jQuery的/ 2010/04 / 解释如何ajaxify您的Zend的形式来显示,例如错误onblur事件上的一个TextInput。

一切正常发现的onblur或以上事件,但是当我指定的提交按钮的单击事件,我的猜测是形式得到由Zend和AJAX验证不起作用处理......你有任何提示或你看到明显的错误? 多谢.... JavaScript的:

  $(函数()
    {
    $('#联系)。递交(函数()
    {
        doValidation();
    });

});

功能doValidation()
{
    VAR URL ='/ ceramstar /公/联系人/ validateform;
    VAR数据= {};
    $(输入)。每个(函数(){
            数据[$(本).attr('名')] = $(本).VAL();

    });


    $。员额(URL,数据功能(RESP)
        {
        //document.write(resp);

                    执行console.log(RESP);
                    警报(RESP);
                    //父$ fancybox.close()。



        },JSON);
}
 

在Zend操作:

 公共职能validateformAction()
{

    $这个 - > _helper-> viewRenderer-> setNoRender();
    $这个 - > _helper->布图设计> disableLayout();
    $形式=新Form_ContactForm();

    $形式 - > isValidPartial($这 - > _getAllParams());
    //的print_r($布尔);
    $ JSON = $形式 - > processAjax($这 - >调用getRequest() - >的getPost());
    标题(内容类型:应用程序/ JSON);
    回声Zend_Json :: EN code($ JSON);
}
 

解决方案

您应该返回false或preventDefault在.submit

 (函数(){
    $('#联系)。递交(函数(){
        doValidation();
        返回false;
    }
});
 

I am currently trying to validate a zend form with ajax and zend validate at the same time...

Let me explain, my forms pops up in an iframe (fancybox) and when submitted, I need to display a "thank you" message, close the iframe and redirect the user. I planned to use ajax validation to close the fancybox iframe if success.

I followed several tutorials http://www.zendcasts.com/ajaxify-your-zend_form-validation-with-jquery/2010/04/ explaining how to ajaxify your zend form to display errors for instance onblur event on a textinput.

Everything works find onblur or over events but when I specify the click event on the submit button, my guess is that the form gets processed by zend and ajax validation doesn't work... Do you have any hints or do you see obvious mistakes?? thanks a lot.... the javascript:

$(function()
    {
    $('#contact').submit(function()
    {
        doValidation();                 
    });

});

function doValidation()
{
    var url = '/ceramstar/public/contact/validateform';
    var data = {};
    $("input").each(function(){
            data[$(this).attr('name')] = $(this).val();

    });


    $.post(url,data,function(resp)
        {
        //document.write(resp);

                    console.log(resp);
                    alert(resp);
                    //parent.$.fancybox.close();



        },"json");
}

the zend action:

public function validateformAction()
{

    $this->_helper->viewRenderer->setNoRender();
    $this->_helper->layout->disableLayout();
    $form = new Form_ContactForm();

    $form->isValidPartial($this->_getAllParams());
    //print_r($bool);
    $json = $form->processAjax($this->getRequest ()->getPost ());
    header('Content-type: application/json');
    echo Zend_Json::encode($json);
}

解决方案

You should return false or preventDefault on the .submit

(function() {
    $('#contact').submit(function() {
        doValidation();
        return false;
    }
});

这篇关于在提交Zend的形式AJAX验证的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆