• 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

A

account8226

Guest
#1
Hey,

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.
 

Chris D

XenForo developer
Staff member
#2
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.
 
A

account8226

Guest
#3
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.
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 ?
 

Chris D

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

PHP:
	if (strlen($username) <= 3)
		{
			$this->error(new XenForo_Phrase('please_enter_a_name_longer_than_3_characters'), 'username');
			return false;
		}
So where it fails the validation, you throw an error with a phrase. That should do it, I think.
 
A

account8226

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

PHP:
 if (strlen($username) <= 3)
{
$this->error(new XenForo_Phrase('please_enter_a_name_longer_than_3_characters'), 'username');
return false;
}
So where it fails the validation, you throw an error with a phrase. That should do it, I think.
Got it thanks, it's what I've done ;)