Jump to:

17452 Posts in 4473 Topics by 1971 members

Archive

SilverStripe Forums » Archive » Filling in a field automatically

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

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

Page: 1
Go to End
Author Topic: 1906 Views
  • cerelac
    Avatar
    Community Member
    34 Posts

    Filling in a field automatically Link to this post

    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.

  • dio5
    Avatar
    Community Member
    501 Posts

    Re: Filling in a field automatically Link to this post

    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));

  • cerelac
    Avatar
    Community Member
    34 Posts

    Re: Filling in a field automatically Link to this post

    Thanks dio5.
    That's exactly what I needed.

    1906 Views
Page: 1
Go to Top

Want to know more about the company that brought you SilverStripe? Then check out SilverStripe.com

Comments on this website? Please give feedback.