Ok. Here's the relevant code in the view file 'users/add.ctp'

echo $form->create('User', array('action' => 'add'));
echo $form->input('first_name', array('label' => '*First name',
'before' => '<br />', 'between' => '<br />', 'after' => '<br />',
'error' => array('wrap' => 'span', 'class' => 'errorMsg'), 'maxlength'
=> '255'));
echo $form->input('last_name', array('label' => '*Last name', 'before'
=> '<br />', 'between' => '<br />', 'after' => '<br />', 'error' =>
array('wrap' => 'span', 'class' => 'errorMsg'), 'maxlength' =>
'255'));
echo $form->input('email', array('label' => '*Email', 'before' =>
'<br />', 'between' => '<br />', 'after' => '<br />', 'error' => array
('wrap' => 'span', 'class' => 'errorMsg'), 'maxlength' => '255'));
echo $form->input('email_confirm', array('label' => '*Confirm email',
'before' => '<br />', 'between' => '<br />', 'after' => '<br />',
'error' => array('wrap' => 'span', 'class' => 'errorMsg'), 'maxlength'
=> '255'));
echo $form->input('password', array('before' => '<br />', 'between' =>
'<br />', 'after' => '<br />', 'error' => array('wrap' => 'span',
'class' => 'errorMsg')));
echo $form->input('password_confirm', array('label' => 'Re-enter
password', 'type' => 'password', 'before' => '<br />', 'between' =>
'<br />', 'after' => '<br />', 'error' => array('wrap' => 'span',
'class' => 'errorMsg')));

..here's the code from the controller....

function add() {
        $this->layout = 'register';
        $this->pageTitle = 'Register';

                if (!empty($this->data)) {
                        if ($user = $this->User->save($this->data)) {
                                $this->Session->setFlash(__('Thanks for 
registering. Now please
log in.', true));
                                $this->redirect(array('action' => 'login'));
                        } else {
                                $this->Session->setFlash(__('Your account could 
not be created.
Please review the errors below and try again.', true));
                        }
                }
        }

... and here's the User model...


<?php
class User extends AppModel {

        var $name = 'User';


    var $validate = array(

                'email' => array(

                'match' => array(
                        'rule' => array('confirmEmail','email'),
                                'message' => 'Your email and email confirmation 
do not
match.',
                ),

                'between' => array(
                                'rule' => array('between', 1, 255),
                                'message' => 'Username must be between 1 and 255
characters in length.',
                        ),

                'validemail' => array(
                                'rule' => 'email',
                                'message' => 'You must supply a valid email
address.',
                        ),

                                'unique' => array(
                                'rule' => 'isUnique',
                                'message' => 'This email address has already 
been
registered.',
                        ),

                        'notEmpty' => array(
                                'rule'=> 'notEmpty',
                                'message' => 'You must supply a valid email 
address.',
                        )),


                'email_confirm' => array(

                'validemail' => array(
                                'rule' => 'email',
                                'message' => 'You must supply a valid email
address.',
                        ),

                        'between' => array(
                                'rule' => array('between', 1, 255),
                                'message' => 'Username must be between 1 and 255
characters in length.',
                        ),

                                'unique' => array(
                                'rule' => 'isUnique',
                                'message' => 'This email address has already 
been
registered.',
                        ),

                        'notEmpty' => array(
                                'rule'=> 'notEmpty',
                                'message' => 'You must supply a valid email 
address.',
                        )),


                        'password' => array(

                'match' => array(
                        'rule' => array('confirmPassword','password'),
                                'message' => 'Your password and password 
confirmation do
not match.'
                ),

                'alphaNumeric' => array(
                                'rule' => 'alphaNumeric',
                                'message' => 'Password can only include 
alpha-numeric
characters.'
                        ),

                                'between' => array(
                                'rule' => array('between', 4, 12),
                                'message' => 'Password must be between 4 and 12
characters in length.'
                        ),

                        'notEmpty' => array(
                                'rule'=> 'notEmpty',
                                'message' => 'You must supply a password.'
                        )),

                        'password_confirm' => array(

                'alphaNumeric' => array(
                                'rule' => 'alphaNumeric',
                                'message' => 'Password can only include 
alpha-numeric
characters.'
                        ),

                                'between' => array(
                                'rule' => array('between', 4, 12),
                                'message' => 'Password must be between 4 and 12
characters in length.'
                        ),

                        'notEmpty' => array(
                                'rule'=> 'notEmpty',
                                'message' => 'You must supply a password.'
                        )),

                        'first_name' => array(

                'alphaNumeric' => array(
                                'rule' => 'alphaNumeric',
                                'message' => 'First name can only include 
alpha-numeric
characters.',
                        ),

                        'between' => array(
                                'rule' => array('between', 1, 255),
                                'message' => 'First name must be between 1 and 
255
characters in length.',
                        ),

                        'notEmpty' => array(
                                'rule'=> 'notEmpty',
                                'message' => 'You must supply a first name.',
                        )),

                'last_name' => array(

                'alphaNumeric' => array(
                                'rule' => 'alphaNumeric',
                                'message' => 'Last name can only include 
alpha-numeric
characters.',
                        ),

                        'between' => array(
                                'rule' => array('between', 1, 255),
                                'message' => 'Last name must be between 1 and 
255
characters in length.',
                        ),

                        'notEmpty' => array(
                                'rule'=> 'notEmpty',
                                'message' => 'You must supply a last name.',
                        )),



        );

        function confirmEmail($data) {
                $valid = false;
                if ($data['email'] == $this->data['User']['email_confirm']) {
                        $valid = true;
                }
                return $valid;
                }

        function confirmPassword($data) {
                $valid = false;
                if ($data['password'] == 
$this->data['User']['password_confirm']) {
                        $valid = true;
                }
                return $valid;
                }


        function hashPasswords($data, $enforce=false) {

           if($enforce && isset($this->data[$this->alias]
['password'])) {
               if(!empty($this->data[$this->alias]['password'])) {
                   $this->data[$this->alias]['password'] =
Security::hash($this->data[$this->alias]['password'], null, true);
               }
           }

           return $data;
        }

        function beforeSave() {
           $this->hashPasswords(null, true);
            return true;
        }
}
?>

On Feb 10, 11:49 am, Gwoo <[email protected]> wrote:
> http://api.cakephp.org/class/validation#method-ValidationequalTo
>
> Also, we have no idea why you get the error because we cannot see the
> code.http://bin.cakephp.org
--~--~---------~--~----~------------~-------~--~----~
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