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

  • Thread starter Thread starter account8226
  • Start date Start date
A

account8226

Guest
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.
 
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.
 
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 ?
 
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.
 
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 ;)
 
Top Bottom