Well first off I would never expose a user_id in a form. (anywhere) My users
do not ever know their id never exposed on the site anywhere. No need for
them to know really.
If they are logged in then you have it in the Session data so you can simply
drop that in behind the scene in the controller

$this->data['ModelName']['user_id'] = $this->Auth-User->('id'); //add this
before you save data

Since you have the user_id you can then find() whatever info you might need
to add to the record, state_id, country_id so on.


$this->Model->save($this->data);


K


-----Original Message-----
From: [email protected] [mailto:[email protected]] On Behalf
Of barricades
Sent: Thursday, February 17, 2011 8:27 PM
To: CakePHP
Subject: how to automatically have the logged in users id in a form

Hi there, I've searched through a bunch of tutorials but no-one seems
to explain this particular situation. I have a model for users and a
model for what I call campaigns, which a logged in user is allowed to
create. So I've got Auth up and running and the relationship set up so
a campaign belongs to a user.

So the user logs in and is directed to the create campaign action. In
the form that the user fills in, I want the users_id to be the id of
the currently logged in user by default.

echo $this->Form->input('user_id');

I know this is probably dead simple, but all the tutorials I've been
through don't tell me. The blog tutorial(s) there is only one possible
user; in the TOR tutorial its a drop down list to select which dealer
etc... etc...

-- 
Our newest site for the community: CakePHP Video Tutorials
http://tv.cakephp.org 
Check out the new CakePHP Questions site http://ask.cakephp.org and help
others with their CakePHP related questions.


To unsubscribe from this group, send email to
[email protected] For more options, visit this group at
http://groups.google.com/group/cake-php

-- 
Our newest site for the community: CakePHP Video Tutorials 
http://tv.cakephp.org 
Check out the new CakePHP Questions site http://ask.cakephp.org and help others 
with their CakePHP related questions.


To unsubscribe from this group, send email to
[email protected] For more options, visit this group at 
http://groups.google.com/group/cake-php

Reply via email to