1. This site uses cookies. By continuing to use this site, you are agreeing to our use of cookies. Learn More.

Validating a form on the fly

Discussion in 'XenForo Development Discussions' started by NixFifty, Dec 30, 2013.

  1. NixFifty

    NixFifty Well-Known Member

    I have a form that loads in an Overlay. That's all working like a breeze however, when it comes to validating the data, that all happens when the form is submitted.

    Could someone point me in to the right direction as to how to validate the data as it is being input. For instance, I'd need to check if the username provided is valid, etc.

    Thanks :)
  2. Chris D

    Chris D XenForo Developer Staff Member

    Validation is done in the DataWriter. Often you won't need to write anything custom for it to happen, e.g. if a value is not entered it will return an error and say a value should be entered. But you can also write your own custom validation steps too using a validation callback or the preSave function in the DataWriter.

    Plenty of examples of that in the existing XenForo DataWriters.

    In terms of triggering those and validating without reloading the page, e.g. running the validation via AJAX, all that is usually required is for your <form> element to have a class of "AutoValidator".
  3. NixFifty

    NixFifty Well-Known Member

    The thing is the form submits the data to a third party through a post action. So from that, I'm assuming a DataWriter can't be used in such an instance?

Share This Page