Sunday, August 2, 2009

Re: Check boxes for a noob

Try inflecting your groupid:

<?php echo $form->input('User.Group', array('type'=>'select',
'value'=>$this->data['User']['groupId'], 'options'=>$groups,
'multiple'=>'checkbox')); ?>

Controllers use the underscore, but views use camelCase, so that might
be what's choking it.

On Aug 2, 11:46 am, Michael Gaiser <mjgai...@gmail.com> wrote:
> So I am trying to get these check boxes to populate correctly and save to
> the DB. (The Select window is too prone to messing things up). Any ideas why
> the check boxes arnt bring checked properly? Also when I change it to just a
> normal select list ('multiple'='true') I still get this:
>
> *Notice* (8): Undefined index:  id [*APP\views\users\admin_edit.ctp*, line *12*]
>
> I would be grateful for any help.
>
> ~Michael
>
> The Controller:
>
>     function admin_edit($id = null) {
>         $groups = $this->User->Group->find("list");
>         $this->set('groups', $groups);
>         if (empty($this->data)) {
>             $this->User->id = $id;
>             $this->data = $this->User->read();
>             $this->data['User']['old_email'] = $this->data['User']['email'];
>         } else {
>             if($this->data['User']['old_email'] !=
> $this->data['User']['email']) {
>                 $this->data['User']['confirm_code'] = String::uuid();
>                 $this->data['User']['confirmed'] = 0;
>             }
>             if($this->User->save($this->data)) {
>                 if($this->data['User']['old_email'] !=
> $this->data['User']['email']) {
>                     if($this->__sendEmail()) {
>                         $this->Session->setFlash('Email has been sent');
>                     } else {
>                         $this->Session->setFlash('Could not send Email');
>                     }
>                 }
>                 $this->flash('Your changes have been
> saved.','/admin/users/view/'.$this->data['User']['id'] );
>             }
>         }
>         debug($groups);
>         debug($this->data);
>     }
>
> The View:
> <h2>Edit User Record (Admin Mode)</h2>
>
> <form method="post" action="<?php echo
> $html->url('/admin/users/edit/'.$this->data['User']['id']); ?>">
>     <?php echo $form->hidden('User.id'); ?>
>
>     <?php echo $form->label('User.username'); ?>
>     <?php echo $form->error('User.username'); ?>
>     <?php echo $form->text('User.username', array('size' => '80' ) ); ?>
>
>     <?php echo $form->label('User.Group', 'User Group (listed according to
> access rights)' ); ?>
>     <?php echo $form->error('User.Group', 'You must select a user group');
> ?>
>     <?php echo $form->input('User.Group', array('type'=>'select',
> 'value'=>$this->data['User']['group_id'], 'options'=>$groups,
> 'multiple'=>'checkbox')); ?>
>
>     <?php echo $form->label('User.name', 'User Full Name'); ?>
>     <?php echo $form->text('User.name', array('size' => '80')); ?>
>     <?php echo $form->error('User.name'); ?>
>
>     <?php echo $form->hidden('User.old_email'); ?>
>     <?php echo $form->label('User.email', 'User E-mail'); ?>
>     <?php echo $form->text('User.email', array('size' => '80')); ?>
>     <?php echo $form->error('User.email'); ?>
>
>     <?php echo $form->label('User.active', 'Active'); ?>
>     <?php echo $form->select('User.active', array('0'=>'No', '1'=>'Yes'));
> ?>
>     <?php echo $form->error('User.active'); ?>
>
>     <?php echo $form->label('User.confirmed', 'Confirmed'); ?>
>     <?php echo $form->select('User.confirmed', array('0'=> 'No',
> '1'=>'Yes')); ?>
>     <?php echo $form->error('User.confirmed'); ?>
>
>     <?php echo $form->hidden('User.passwd'); ?>
>
>     <?php echo $form->error('User.new_passwd'); ?>
>
>     <?php echo $form->submit('Save Changes'); ?>
> </form>
--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups "CakePHP" group.
To post to this group, send email to cake-php@googlegroups.com
To unsubscribe from this group, send email to cake-php+unsubscribe@googlegroups.com
For more options, visit this group at http://groups.google.com/group/cake-php?hl=en
-~----------~----~----~----~------~----~------~--~---

No comments: