I have a model with start_date and end_date attributes , and I need to check against my database, if this period overlaps any existing one, with a function I’ve created. My question is… how can I add this function as a custom validation rule in my model, and what does it needs to return so I can see the error message in my view as it was a default validation one?
class BusinessConnectionValidation extends CValidator
{
protected function validateAttribute($object, $attribute)
{
// extract the attribute value from it's model object
if($object->businessConnection == 'yes')
{
if(empty($object->companyName))
{
$this->addError($object,'companyName','fill in pls');
}
if(empty($object->kvkNumber))
{
$this->addError($object,'compantAddress','fill in pls');
}
}
}
It works fine, but only server side.
How do I get it to work on the client side?
I have tried ‘enableClientValidation’=>true but validation is still done once the page is submitted.
I want to create cutomize rule for my model, which check for both client side as well as server side.
I have used this code.
array('tags', 'validateTags','on'=>'insert'),//require only on insert
and write function for validateTags but its work for server side validation not for client side validation. What should i do to for both the side validation.
public function validateTags($attribute,$params)
{
.............................
.........................
}