Best way to validate a custom form


Well-known member
Currently I have a form that members can submit data into. After they submit the form I need to verify "some" of the data exists, and is valid, before proceeding. If that data is invalid, or non-existent, I need to show them an error. How can process the data, via AJAX, and give them the "please correct the following errors" popup?

Also, in case it matters, none of this data is being written into the database "as is".


Well-known member
Possibly the best place to look is the registration form

They verify each field against the DataWriter (via ajax)... but, it doesn't need to be a datawriter, this is just where the verification is done in this case

The format of the email address is checked, datatype and string length is checked.

Look at XenForo_ControllerPublic_Register and then look at the DataWriter that it checks:


You'll notice a verification field such as:

'verification' => array('$this', '_verifyUsername')
and a protected function _verifyUsername(&$username) is later mentioned within that file


Well-known member
Thanks for the reply, guys. I think all I need to know is how to return a response that there were errors during validation.

Here is the error I'm getting, currently: No controller response from myAddon_ControllerPublic_Index::actionSave

@tentants: Thanks for the reply. I've tried doing something similar to that all day long, without any luck. I guess I'm simply not smart enough to see what's going on in there. :confused:

@Jake Bunce: Thanks for that reply too, but I'm not sure I want to create a custom profile field for every option that I'll have on this form.


Well-known member
If I use return $this->responseError($error); in my script I no longer get the error. Instead of giving the error "popup", though, it just takes me to a new page that lists the errors.