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

Best way to validate a custom form

Discussion in 'XenForo Development Discussions' started by mjda, Jun 1, 2013.

  1. mjda

    mjda Active 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".
     
  2. tenants

    tenants 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:

    XenForo_DataWriter_User

    You'll notice a verification field such as:

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

    Jake Bunce XenForo Moderator Staff Member

  4. mjda

    mjda Active 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.
     
  5. mjda

    mjda Active 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.
     
  6. mjda

    mjda Active Member

    Doh! I didn't have the "AutoValidator" class inserted. Thanks again for the help, guys. Hopefully I've got it now. :)
     
    tyteen4a03 and tenants like this.

Share This Page