Wednesday, August 26, 2009

Re: FormHelper Select

Thank you! I really appreciate it. :)

On Aug 25, 8:31 pm, delocalizer <conrad.leon...@hotmail.com> wrote:
> Hi Sarah;
> If you declare in your user model file:
> var $displayField = 'username';
> then find('list') returns an array with keys of id's and values of
> usernames...
> and then if you have in your view:
> $form->input('user_id',$users);
> cake automatically generates a  select-type input field for user_id
> from your list of $users, with labels being usernames and values as
> ids. So the value of user_id is assigned automatically to an id - no
> need for another query.
>
> cheers,
> C.
>
> On Aug 26, 9:13 am, Sarah <sarah.e.p.jo...@gmail.com> wrote:
>
> > I have an add form for "userpages".  Each user hasMany userpages.
>
> > I want a list of the usernames to be in the select list, but I want
> > the foreign key user_id to be stored in the userpages table.
>
> > The hasMany relationship is already set up.
>
> > In my controller I have:
>
> > $users = $this->Userpage->User->find('list');
>
> > $this->set(compact('users'));
>
> > Then in my view:
>
> > $form-select('User.username', $users);
>
> > but a select  box with the user_id's is displayed instead.
>
> > How can I get the list of usernames to be displayed, and once I have
> > the usernames in the select do I get the selected username and then
> > make a query for that user's id and store that as the user_id?
>
> > I appreciate all advice.
>
> > Thanks,
> > ~Sarah
--~--~---------~--~----~------------~-------~--~----~
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: