Jump to:

23459 Posts in 18906 Topics by 2877 members

General Questions

SilverStripe Forums » General Questions » Appropriate approach to failed server side validation return to ajax?

General questions about getting started with SilverStripe that don't fit in any of the categories above.

Moderators: martimiz, Sean, biapar, Willr, Ingo, swaiba, simon_w

Page: 1
Go to End
Author Topic: 150 Views
  • flipsidenz
    Community Member
    49 Posts

    Appropriate approach to failed server side validation return to ajax? Link to this post

    I have a form on a site I am building which is posted via ajax. It first runs through jQuery validate plugin validation, and on success POSTS through ajax.

    If the form has been filled out correctly, all works well. But if for whatever reason client-side validation succeeds when it shouldn't have, when the ajax POST is made, the form detects a validation error (e.g. blank required name) & returns the full template HTML for the rendered page.

    Because Ajax is POST'ing the form data, is there a way to manipulate the response? Rather than sending through the template HTML, return an json object of validation errors?

    Looking into framework's form.php, I see the method getValidationErrorResponse. I guess I could subclass form and write my own getValidationErrorResponse to manage how the response is handled? However, is there something already pre-built into SS to manage this type of situation?

Page: 1
Go to Top

Want to know more about the company that brought you SilverStripe? Then check out SilverStripe.com

Comments on this website? Please give feedback.