I'm not entirely sure of all the differences, but what I am learning
is it is best to go "as-Cake-as-possible" to get everything to tie
together. It's worth persevering until you find the solution. One
thing I do know is that if you use $form->input everything is wrapped
up in a div. If you use $form->label etc it isn't which means you have
to do it yourself (more code/markup etc = bad!).

On Nov 18, 3:35 pm, E T <[email protected]> wrote:
> Wow, amazing!! You are a genius.. hehe thank you so much.
>
> It is working now, and yes you are right, I forgot to make changes in the
> view.
>
> BTW, just one curious question.. so to create input fields in form, it is
> better to use '$form->input' rather than something like '$form->password' ?
> What is the difference?
>
> Thank you.
>
>
>
> On Wed, Nov 18, 2009 at 11:09 PM, jburns <[email protected]> wrote:
> > First, change the inputs in the view to:
>
> > echo $form->input('password1', array('label'=>'Password'));
> > echo $form->input('password2', array('label'=>'Please confirm your
> > password'));
>
> > See what happens then.
>
> > On Nov 18, 2:57 pm, E T <[email protected]> wrote:
> > > Hi jburns,
>
> > > Thanks a lot for the reply. I've tried adding your code but it's still
> > not
> > > working.
>
> > > This is what happened:
> > > - if name, email or username is empty, it will give an error message,
> > > something like "Alphabets and numbers only" or "This field cannot be left
> > > blank". However, there is no error message for password1 / password2.
> > > - then I try to input everything. And when I click on save, the page
> > doesn't
> > > load anything. It's still on the same page, and my 'users' table is not
> > > updated.
> > > - if I remove the validation for password1 & password2 in the model's
> > > $validate, it saves the data to db and redirect to other page (working
> > > fine).
>
> > > I'm not sure what's wrong with this.
>
> > > On Wed, Nov 18, 2009 at 10:10 PM, jburns <[email protected]> wrote:
> > > > I forgot something...you need to clear out the password1 and password2
> > > > fields before saving. Use this:
>
> > > > function beforeSave() {
> > > >                if (isset($this->data['User']['password1'])):
> > > >                        $this->data['User']['password'] =
> > > >  Security::hash($this->data
> > > > ['User']['password1'], null, true);
> > > >                        unset($this->data['User']['password1']);
> > > >                endif;
>
> > > >                if (isset($this->data['User']['password2'])):
> > > >                        unset($this->data['User']['password2']);
> > > >                endif;
>
> > > >                return true;
> > > >         }
>
> > > > On Nov 18, 2:06 pm, jburns <[email protected]> wrote:
> > > > > 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]<cake-php%[email protected]
> > > >  om>
> > <cake-php%[email protected] om>
> > > > .
> > > > For more options, visit this group at
> > > >http://groups.google.com/group/cake-php?hl=.
>
> > --
>
> > 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]<cake-php%[email protected] 
> > om>
> > .
> > For more options, visit this group at
> >http://groups.google.com/group/cake-php?hl=.

--

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