Thanks Martin, I will give this one a trie. On first glance it should
work perfect.

On 1 Sep., 16:54, "[EMAIL PROTECTED]"
<[EMAIL PROTECTED]> wrote:
> For editable fields, like email, that should be unique, you need the
> validation on the updates aswell... I have used a custom validation
> that basically checks if there is a record with the same email but a
> different id. If you only check on create then you should prevent it
> from being edited later.
>
> I have this custom function in my AppModel.
> Can't remember if I wrote this myself or if I found it somewhere. To
> the original author I apologize that I can't remember their name.
>
> function _isUnique($field, $value)
> {
>     $conditions = array($this->alias.'.'.$field => $value);
>
>     if(isset($this->data[$this->name][$this->primaryKey])) // if this
> is an update, only look for records other than this one
>     {
>         $conditions[$this->alias.'.'.$this->primaryKey] = '<> 
> '.$this->data[$this->alias][$this->primaryKey];
>
>     }
>
>     $results = $this->find('first',array(
>             'conditions'=> $conditions,
>             'recursive'=>'-1'
>         )
>     );
>
>     if(!empty($results))
>     {
>         return false;
>     } else {
>         return true;
>     }
>
> }
>
> On Sep 1, 4:45 pm, Preloader <[EMAIL PROTECTED]> wrote:
>
> > Hello again,
>
> > ahm, may be you should put
>
> > ‘on’ => ‘create’
>
> > to the validation rule of the email.
>
> > So the isUnique rule only applies, when creating a new user record,
> > not when updating it.
>
> > Have a look here:http://book.cakephp.org/view/125/data-validation#on-131
>
> > Regards, Christoph
>
> > On 1 Sep., 16:37, worthy <[EMAIL PROTECTED]> wrote:
>
> > > Hi Preloader and thanks for the fast answer.
>
> > > I now added some more hidden fields and used the right name setting.
>
> > > <?=$form->input('Customer.id', array('type'=>'hidden'));?>
> > > <?=$form->input('Customer.user_id', array('type'=>'hidden'));?>
> > > <?=$form->input('User.id', array('type'=>'hidden'));?>
>
> > > This way the validation array looks like this:
> > > Array
> > > (
> > >     [User] => Array
> > >         (
> > >             [email] => [EMAIL PROTECTED]
> > >             [id] => 9
> > >         )
>
> > >     [Customer] => Array
> > >         (
> > >             [firm] => -
> > >             [first_name] => Xxx
> > >             [last_name] => Xxx
> > >             [street] => Xxxx
> > >             [nr] => 8
> > >             [plz] => 01234
> > >             [ort] => Xxxx
> > >             [id] => 8
> > >             [user_id] => 9
> > >         )
>
> > > )
>
> > > I now tried 2 different validations with this array and both fail and
> > > tell me, that the email already exists.
> > > Those 2 are:
>
> > > NR1:
> > > -------
> > > $cleandata = $this->htmlchars($this->data);
>
> > > $this->User->data=$cleandata;
> > > $this->Customer->data=$cleandata;
>
> > > if($this->User->validates($cleandata) && $this->Customer-
>
> > > >validates($cleandata)) { ... }
>
> > > NR2:
> > > -------
> > > $cleandata = $this->htmlchars($this->data);
>
> > > $this->User->data=$cleandata;
> > > $this->Customer->data=$cleandata;
>
> > > if($this->Customer->User->validates($cleandata) && $this->Customer-
>
> > > >validates($cleandata)) { ... }
>
> > > As I said above both of them fail.
>
> > > I did not try saveAll() yet because I have to make the validation work
> > > first.
>
> > > Greetings worthy
--~--~---------~--~----~------------~-------~--~----~
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