First, a general point. Rather than having separate entries for label
and the input, try:
echo $form->input('xxx', array('label'=>'Xxxx'));
(where xxx is the name of your field and Xxxx is your label).

This works for me when confirming that passwords match:

'password1'=>array(
                        'password_1'=>array(
                                'rule'=>'notEmpty',
                                'message'=>'Please enter a password.',
                                'required'=>true,
                                'last'=>true),
                        'password_2'=>array(
                                'rule'=>array('between', 8, 20),
                                'message'=>'Your password must be between 8 and 
20 characters
long.'),
                ),
                'password2'=>array(
                        'match'=>array(
                                'rule'=>'validatePasswdConfirm',
                                'required'=>true,
                                'allowEmpty'=>false,
                                'message'=>'Your passwords do not match')
                )

You'll notice that the rule for validating password2 is
'validatePasswdConfirm'. Place this function in your model:

        function validatePasswdConfirm($data) {
                if ($this->data['User']['passwd'] !== $data['passwd_confirm']):
                        return false;
                endif;

                return true;
        }

For the role field, it looks as if your syntax is a bit muddled. Try
something along these lines:

echo $form->input('role', array('type'=>'select', 'empty'=>true,
'options'=>$roles, 'label'=>'Role'));

$options is the array that contains the allowed values and can be set
in the controller - particularly useful if you are extracting them
from a table.

Hope this helps.

On Nov 18, 10:44 am, Code Buzz <[email protected]> wrote:
> Hi all,
>
> I'm a newbie at cakePHP, and still at the learning phase.
>
> I was trying to make a user management system with cakephp, where we
> can add/edit/delete user. But I am stuck in the validation part. I
> hope someone can help me on this.
>
> I have this 'users' table:
> =========================
> CREATE TABLE `users` (
>   `id` int(11) NOT NULL AUTO_INCREMENT,
>   `username` varchar(255) NOT NULL,
>   `password` varchar(32) NOT NULL,
>   `email` varchar(80) NOT NULL,
>   `name` varchar(255) NOT NULL DEFAULT '',
>   `designation` varchar(255) DEFAULT NULL,
>   `role` varchar(30) NOT NULL,
>   `print_perm` int(1) NOT NULL,
>   `disabled` int(1) NOT NULL DEFAULT '0',
>   PRIMARY KEY (`id`)
> ) ENGINE=MyISAM AUTO_INCREMENT=1 DEFAULT CHARSET=latin1;
>
> and I have this form to add the user:
> =========================
>   echo $form->create('User');
>   echo $form->input('username');
>   echo $form->input('email');
>   echo $form->input('name');
>   echo $form->input('designation');
>   $options=array('admin'=>'Administrator','user'=>'User');
>   echo $form->label('Role');
>   echo $form->select('role',$options);
>   echo $form->label('Password');
>   echo $form->password('password1');
>   echo $form->label('Confirm Password');
>   echo $form->password('password2');
>   echo "<br>";
>   echo $form->checkbox('print_perm');
>   echo "<span class='text-bold'> Can Print?</span><br><br>";
>   echo $form->input('id', array('type'=>'hidden'));
>   echo $form->button('Save', array('type' => 'submit'));
>   echo $form->button('Reset', array('type' => 'reset'));
>   echo $form->end();
>
> I put this validation on my model:
> =========================
>     var $validate = array(
>         'username' => array(
>             'alphaNumeric' => array(
>                 'rule' => 'alphaNumeric',
>                 'message' => 'Alphabets and numbers only'
>                 ),
>         ),
>         'email' => 'email',
>         'name' => VALID_NOT_EMPTY,
>         'role' => VALID_NOT_EMPTY,
>         'password' => VALID_NOT_EMPTY,
>     );
>
> it is not working for the 'role' and 'password' field. I have
> 'password1' and 'password2' in the view, while my db field is
> 'password'. I'm not sure what to do to make this work.
>
> Any help is appreciated. Thank you.

--

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=.


Reply via email to