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

When do you check your date validity before inserting it to DB

Discussion in 'XenForo Development Discussions' started by account8226, Jan 3, 2013.

  1. account8226

    account8226 Guest


    I am actually checking if my data is valid in my DWriter.

    For example, if var is too long return error.

    Is it good ? Or do I have to make the check before the DW ?

    Best regards.
  2. Chris D

    Chris D XenForo Developer Staff Member

    The DataWriter is usually the most appropriate place.

    As you can see from the User DataWriter in XenForo. There's a heck of a lot of validation checks in there for the various user fields.
    Elly likes this.
  3. account8226

    account8226 Guest

    Great thanks you Chris ! And sometimes my validateForm return 'Please check your data'. Is there anyway to get more informations to the user, like which field isn't allright ?
  4. Chris D

    Chris D XenForo Developer Staff Member

    It depends, but typically you would do something like this... If you're trying to verify if the username is longer than 3 characters:

        if (strlen($username) <= 3)
    $this->error(new XenForo_Phrase('please_enter_a_name_longer_than_3_characters'), 'username');
    So where it fails the validation, you throw an error with a phrase. That should do it, I think.
    Elly likes this.
  5. account8226

    account8226 Guest

    Got it thanks, it's what I've done ;)

Share This Page