Zend form ajax validation on submit

Deadly 提交于 2019-12-21 05:35:36

问题


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);
}

回答1:


You should return false or preventDefault on the .submit

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


来源:https://stackoverflow.com/questions/5620371/zend-form-ajax-validation-on-submit

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!