Hi all, 

Is it possible to have model validation only be called when there is an add
action and not edit for example ?

I have added unique name validation but now with the edit of a record it
still gives a validation error as that name of that record already exists.

My code as follows: 

        var $validate = array(
                                'question' => array(
                          'Question already exists, please enter a unique
question' => array(
                                               'rule' => array(
                                                               'isUnique',
'question'
                                                               )
                                             ),
                          'This field cannot be left blank' =>
VALID_NOT_EMPTY                   
                          ),

 function isUnique($field, $value) {
    
    $fields[$this->name.'.'.$value] = $field[$value];
    $this->recursive = -1;
    
    if ($this->hasAny($fields)) {
      $this->invalidate('unique_'.$field);
      return false;
    } else {
    
      return true;
    }
  }

thanks in advance.

-- 
View this message in context: 
http://www.nabble.com/validation-in-model-tp20767005p20767005.html
Sent from the CakePHP mailing list archive at Nabble.com.


--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups 
"CakePHP" group.
To post to this group, send email to [email protected]
To unsubscribe from this group, send email to [EMAIL PROTECTED]
For more options, visit this group at 
http://groups.google.com/group/cake-php?hl=en
-~----------~----~----~----~------~----~------~--~---

Reply via email to