Some Snipp for user model: function beforeValidate() { if ( isset($this->data[$this->name]['password']) && isset($this- >data[$this->name]['password2']) ) { # invalidate empty password2 if ( empty($this->data[$this->name]['password2']) ) { $this->invalidate('password2'); return false; } # invalidate password2 dont match password elseif ( $this->data[$this->name]['password2'] != $this->data[$this- >name]['password'] ) { $this->invalidate('password2_match'); return false; } # OK elseif( $this->data[$this->name]['password'] === $this->data[$this- >name]['password2'] ) { $this->data[$this->name]['password'] = md5($this->data[$this- >name]['password']); $this->data[$this->name]['password2'] = md5($this->data[$this- >name]['password2']); return true; } } # registration = false => skip validation else { return true; }
return true; } AND view template: <?php echo $html->password('User/password') ?> <?php echo $html->tagErrorMsg('User/password', 'Pls. ent.pass') ? > <?php echo $html->password('User/password2') ?> <?php echo $html->tagErrorMsg('User/password2', 'Please confirm pass!') ?> <?php echo $html->tagErrorMsg('User/password2_match', 'Pass. don't match') ?> On Nov 25, 7:22 pm, oracle411 <[EMAIL PROTECTED]> wrote: > I want users to enter their password twice to validate it, and I do so > with the code below. But it seems that I need to have two field in my > DB table in order to have this work (password and confirm_password). > Since I only will use the confirm_password field once, I rather not > store it in my DB. I would like to just be able to retrieve the data > and do a comparison and the forget about the confirm_password > field. > > Is their a way of doing this or do I need both fields in my Clients > table? > > ----------------------------------------------------------------------------------------------------------------------------------- > code: > > controller: > > function index() > { > if(!empty($this->data['Client'])) { > if($this->Client->isConfirm('password', > $this->data['Client'] > > ['password'],$this->data['Client']['confirm_password'])) > { > if ($this->Client->save($this->data)) > { > $this->flash('Your post has been saved.','/ > clients/ > register2'); > } > } > } > } > > Model > > function isConfirm($field,$v1,$v2) { > if($v1 != $v2) { > $this->invalidate('confirm_'.$field); > return false; > } else return true; > } > > var $validate = array( > 'email' => VALID_NOT_EMPTY, > 'fname' => VALID_NOT_EMPTY, > 'lname' => VALID_NOT_EMPTY, > 'username' => VALID_NOT_EMPTY, > 'password' => VALID_NOT_EMPTY, > 'confirm_password' => VALID_NOT_EMPTY, > 'contact1' => VALID_NOT_EMPTY > > ); > > Views > > Password > <?php echo $html->tagErrorMsg('Client/password', > 'Password is > required.') ?> > <?php echo $html->input('Client/password', > array('size' => '10'))?> > <p> > > Confirm Password > <?php echo $html->tagErrorMsg('Client/ > confirm_password', 'Password > Mismatch.') ?> > <?php echo $html->input('Client/confirm_password', > array('size' => > '10'))?> <p> --~--~---------~--~----~------------~-------~--~----~ You received this message because you are subscribed to the Google Groups "Cake PHP" group. To post to this group, send email to cake-php@googlegroups.com 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 -~----------~----~----~----~------~----~------~--~---