Validating a form on the fly

Naz

XenForo developer
Staff 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 :)
 
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".
 
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".
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?
 
Back
Top Bottom