views:

119

answers:

3

is there any mistake in this validation???

 var $validate = array(
  'brand_id' => array(
   'required' => array(true),
   'message' => array('select a brand'),
  )
    );

brand_id is a select box
It show error as "message" instead of "select a brand"
if the message is not in array it shows error

Warning (2): preg_match() [function.preg-match]: Delimiter must not be alphanumeric or backslash [CORE\cake\libs\model\model.php, line 2571]

using cakePHP 1.3

+2  A: 

You're missing a rule, just required won't do. Use 'notEmpty' as rule if that's what you want. Also, required and message should (must?) not be arrays.

deceze
can u provide me an example of rule for select box???
RSK
@RSK That depends entirely on what the value should be. It doesn't matter that it's a select box, the rule is there to verify what values are allowed to go into your database and which aren't. Pick any rule that fits your bill: http://book.cakephp.org/complete/1143/Data-Validation#Core-Validation-Rules-1152
deceze
@deceze thanks dude comparison rule worked 'rule' => array('comparison', '>', 0),
RSK
+1  A: 

Why do you have arrays everywhere?

 var $validate = array(
  'brand_id' => array(
   'required' => true,
   'message' => 'select a brand',
  )
);

Refer to: http://book.cakephp.org/view/125/Data-Validation

quantumSoup
Already explained it in my question
RSK
+1  A: 

http://variable3.com/blog/2010/03/validation-required-vs-allowempty/

try this to understand how it works

Harsha M V