Jeroen
Jeroen

Reputation: 267

Magento ajax form validation

I have a form in Magento that I build in code, and that works with ajax, which I need to validate.

I would like to be able to use Magento's built-in validation functionality, but I don't know how I would trigger it since the form is not submitted. The data is retrieved via ajax and outputted in a list below the form.

Is there someone who can point me in the right direction?

Thanks in advance.

Edit:

This is the javascript code used to hande the ajax request. Its called by the onclick event of the button.

function advancedtranslateSearch(url){  
    new Ajax.Request(url, {
      method: 'get',
      parameters: $('search_form').serialize(),
      onSuccess: function(transport) {
          json = transport.responseText.evalJSON();
          $('result').update('<div class="hor-scroll">'+json.records+'</div>');
      }
    });
}

Upvotes: 1

Views: 3160

Answers (1)

Roman Snitko
Roman Snitko

Reputation: 3655

You should use form's onsubmit event. To prevent page from reloading you must return false value from your function.

Upvotes: 1

Related Questions