I have a model with the fields: Permitted_quantity and issued_quantity.
What i want is after the user has entered the values and clicks on submit i need it to be checked if the issued_quantity that has been entered is less than the permitted_quantity. If not i want an alert box or a message displayed saying "the permitted limit has been crossed. "
Just for clarification, do you wan to show the error message or suppress it?
If you want to show the error message, I think you can use of a validation method in your model like this:
public function rules()
{
return array(
...
array('issued_quantity', 'quantity_check'),
);
}
public function quantity_check($attribute,$params)
{
if( $this->issued_quantity > $this->Permitted_quantity)
$this->addError('issued_quantity','the permitted limit has been crossed.');
}
It’s ajax ready.
Check the guide : Working with Forms > Creating Model > Declaring Validation Rules.