K
K
KoRNeT46RuS2016-02-16 11:38:27
Zend Framework
KoRNeT46RuS, 2016-02-16 11:38:27

ZF2 validation filter fails on ajax request?

When sending data by Ajax, by clicking on submit, the input filter does not work (does it not display a message saying that the password in the input is too short or the required field is empty at all)? I can't figure out why

form.find('.js-event-submit').on('click', function(){
        var dataForm = form.serialize();
        $.ajax({
            type: 'POST',
            url: form.attr('action'),
            dataType: 'json',
            data: dataForm,
            success: function(data){
                if(data.completeRegistration) {
                    form.find('.js-event-success').show();
                }
                console.log(data);
            }
        });

        return false;
    });

But there is an interesting feature. If you remove return false, then the filters work, but the page is reloaded when sending

Answer the question

In order to leave comments, you need to log in

1 answer(s)
C
Cat Anton, 2016-02-16
@27cm

When sending data by Ajax, by clicking on submit, the input filter does not work (does not display a message saying that the password in the input is too short or the required field is empty in general)

And why on earth should error messages be displayed? You should receive these messages with JavaScript and arrange them yourself. What outputs console.log(data);? What does an AJAX request handler return? Hopefully JSON/XML and not HTML?
Not surprising. By removing return false, the submit button starts working in the standard way - it sends a request to the server with a page reload.

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question