Skip to main content

This site requires you to update your browser. Your browsing experience maybe affected by not having the most up to date version.

Archive

Our old forums are still available as a read-only archive.

Moderators: martimiz, Sean, biapar, Willr, Ingo, simon_w

Filling in a field automatically


Reply

3 Posts   1978 Views

Avatar
cerelac

7 June 2008 at 2:37am Community Member, 34 Posts

Hi everyone.

I would like to know if it's possible to fill the Author field of the ArticlePage example (tutorial 2), automatically.
I was thinking about some way to identify the username that is adding the content (something like a $username variable), and fill the DB field with his/her username without typing it (without filling the author field with his/her name manually).

Best regards.

Avatar
dio5

7 June 2008 at 8:18am Community Member, 501 Posts

Yes, sure this is possible.

Just do something like this in the getCMSFields function:

$member = Member::currentUser();
$fields->addFieldToTab("Root.Content.Main", new TextField("Author", "Author", $member->FirstName . " " . $member->Surname));

Avatar
cerelac

9 June 2008 at 10:33pm Community Member, 34 Posts

Thanks dio5.
That's exactly what I needed.