Reputation: 573
I am working on cakephp framework,where mysql is back end.I am developing form to enter product details,where product_id is to be added manually.I have written the validation rules for product_id field.It works for other validation rules i.e. for not empty, numeric.But not working for unique validation rule.Here is my validation code in the model:
var $validate= array(product_id=>
'numeric'=> array('rule'=>'numeric',
'on'=>'create',
'message'=>'Please enter only numbers'),
'isUnique' => array('rule' => 'isUnique',
message' => 'This product_id already exist'),
'notEmpty'=> array('rule' => 'notEmpty',
message' => 'Please enter the product id')),
'product_name' => array('notEmpty'=> array(
'rule' => 'notEmpty',
'message' => 'Please enter the product name')));
I couldn't able to point out the error location.
Upvotes: 0
Views: 373
Reputation: 17967
Shouldn't it be:
var $validate= array('product_id'=> array('rule'=>'numeric',
'on'=>'create',
//etc
Else you are attempting to validate a field called numeric
?
Also, whilst I don't know how your app functions, using product_id
sounds like it should relate to another record, in the products
table - which would be automatically dealt with with Cake i.e. in a select.
If you are entering a unique code (such as an internal Reference number), consider renaming the field to something less-Cake-like to prevent any issues that may arise, or confusion with another Cake developer.
Upvotes: 3