I have model rules() like below, but it is not working. It is showing error message always.
public function rules()
{
return [
[['start_date','end_date'], 'date', 'format' => 'php:F d Y'],
['start_date','compare','compareAttribute'=>'end_date','operator'=>'<'],
['end_date','compare','compareAttribute'=>'start_date','operator'=>'>'],
];
}
public function rules()
{
return [
[['start_date','end_date'], 'date', 'format' => 'php:F d Y'],
['start_date','validateDates'],
];
}
public function validateDates(){
if(strtotime($this->end_date) <= strtotime($this->start_date)){
$this->addError('start_date','Please give correct Start and End dates');
$this->addError('end_date','Please give correct Start and End dates');
}
}
you should write Client-Side Validation. http://www.yiiframework.com/doc-2.0/guide-input-validation.html#client-side-validation
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With