matzehahn

Thanks for this link. Unfortunately this source don't worked with my
edit-function (add worked).
I tryed to change the source, but without success.



BrendonKoz

Thanks also for your help. I tryed some hours to get all this working
but also without success.


Fortunately, i found a link to a nice validate function: (http://
bin.cakephp.org/view/653776884   -> Thanks a lot to the author!!!)
This code works for my with add and edit.
I simply included a 'notEmpty' rule and it was done. :)

So here is my source:
[code]
var $validate = array(
      'location_id' => array(
        /* In the parameters, after 'description', there can be added
more fields to validate */
          'rule' => array('noDuplicates',
            array('description', 'location_id')),
            'message' => 'this combination of Location and Description
is already in use'
      ),
      'description' => array(
                    'rule' => 'notEmpty',
        'message' => '"Description" cannot be left blank'
                  )
   );


   /* Checks to see if there is already a duplicate of the specific
combination of fields */
   function noDuplicates($value, $params)
   {
      /* if editing an existing record then don't count this record in
the check for duplicates */
      if (!empty($this->id))
          $conditions[] = array($this->primaryKey . ' <>' => $this-
>id);

      /* Add a condition for each field we want to check against */
      foreach ($params as $field)
      {
          /* check if value is empty. if it is then check for a NULL
value against this field */
          if($this->data[$this->name][$field])
              $fieldVal = $this->data[$this->name][$field];
          else
              $fieldVal = null;
          $conditions[] = array($field => $fieldVal);
      }

      $existingFieldsCount = $this->find( 'count', array('conditions'
=> $conditions, 'recursive' => -1) );
      return $existingFieldsCount < 1;
   }
[\code]

The function can by included in the current model or in the app_model.

Greetings! :)

Check out the new CakePHP Questions site http://cakeqs.org and help others with 
their CakePHP related questions.

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

Reply via email to