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.

We've moved the forum!

Please use forum.silverstripe.org for any new questions (announcement).
The forum archive will stick around, but will be read only.

You can also use our Slack channel or StackOverflow to ask for help.
Check out our community overview for more options to contribute.

Archive /

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

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

Filling in a field automatically


Go to End


3 Posts   2431 Views

Avatar
cerelac

Community Member, 34 Posts

7 June 2008 at 2:37am

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

Community Member, 501 Posts

7 June 2008 at 8:18am

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

Community Member, 34 Posts

9 June 2008 at 10:33pm

Thanks dio5.
That's exactly what I needed.