Jump to:

23486 Posts in 18995 Topics by 2878 members

General Questions

SilverStripe Forums » General Questions » Is User Registration Possible?

General questions about getting started with SilverStripe that don't fit in any of the categories above.

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

Page: 1
Go to End
Author Topic: 3803 Views
  • craig-oeuk
    Community Member
    1 Post

    Is User Registration Possible? Link to this post

    I'm struggling to find any documentation in regards to getting users to sign up.

    There seems to be a bunch of security/authentication stuff but nothing which actually tells me how to set up users in a SilverStripe project?

  • TerryMiddleton
    Community Member
    108 Posts

    Re: Is User Registration Possible? Link to this post

    Oh yes, very easily.

    You are going to create a new page (I called mine RegistrationForm.php) and save it in you mysite/code/RegistrationForm.php

    See my RegistrationForm.php below.

    Then you need to create a RegistrationForm.ss and save that in your project/templates/RegistrationForm.ss

    The RegistrationForm.ss will look similar (if you want) to the Page.ss. The main variable you need in this page is $Form which is passed from the RegistrationForm.php

    If you need to include the email notification like I did you will want to create a RegistrationFormEmail.ss that is used to format the email that gets sent.

    Notice in the RegistrationForm.php there is a setTemplate that directs the page to use RegistrationFormEmail.ss as the template as well as the RegistrationForm.ss.

    I hope this helps. You can see it in action if you would like at


    class RegistrationForm extends Page {

    class RegistrationForm_Controller extends Page_Controller {

       // Make sure you set this to the right group.
       // See http://doc.silverstripe.com/doku.php?do=show&id=recipes%3Aforms
       private $defaultGroupID = 2;

       * This function lets you put a form on your page, using $Form.
       function Form() {
          return new Form($this, "Form", new FieldSet(

             // List your fields here
             new EmailField("Email", "Email address"),
             new PasswordField("Password", "Create a Password"),
             new TextField("FirstName", "First name"),
             new TextField("LastName", "Last name"),
             new TextField("Phone", "Phone"),
             new TextField("Company", "Company/Hospital"),
             new TextField("Address1", "Address 1"),
             new TextField("Address2", "Address 2"),
             new TextField("City", "City"),
             new TextField("State", "State"),
             new TextField("Zip", "Zip"),
             new TextField("Country", "Country"),
             new ReadonlyField("IPAddress","IPAddress",$_SERVER['REMOTE_ADDR'])

          ), new FieldSet(

             // List the action buttons here
             new FormAction("SignupAction", "Submit")

          ), new RequiredFields(

             // List the required fields here: "Email", "FirstName"
             "Email", "Password", "FirstName", "LastName", "Phone", "Company", "Address1", "City", "State", "Zip", "Country"


       * This function is called when the user submits the form.
       function SignupAction($data, $form) {

          // Create a new Member object and load the form data into it
          $member = new Member();

          // Write it to the database. This needs to happen before we add it to a group

          // Add the member to group. (Check if it exists first)
          if($group = DataObject::get_one('Group', "ID = 2")) {

             // Redirect to a page thanking people for registering
             //Set data
                $From = $data['Email'];
                $To = "email address of who gets the email, 2nd email addres";
                $Subject = "Registration Request";
                $email = new Email($From, $To, $Subject);
                //set template
                //populate template
                //send mail
             //$e = new Email();
             //$e->To = "terry@thestoreinsider.com";
             //$e->Subject = "Registration Request";
    //         $e->Body = populateTemplate($data);

             //$e->Body = $member;


             // Redirect to a failure page




  • AdamJ
    Community Member
    145 Posts

    Re: Is User Registration Possible? Link to this post

    Terry, when you post code, its best to surround it with [ code ][ /code ] tags, it displays better and makes it easier to read

  • TerryMiddleton
    Community Member
    108 Posts

    Re: Is User Registration Possible? Link to this post

    Thanks for this. I will do this next time.


  • rpw2
    Community Member
    6 Posts

    Re: Is User Registration Possible? Link to this post

    Hi Terry, thanks for the example. Can you explain more about how and where the additional member data fields are processed and saved (which table). By following the example I can save names, email and password (all fields are displayed in form) into existing member table and assign to a group but am I missing something here ($db?) to save additional fields??? Thanks.
    nb: I have added a similar question to another post too.

  • rpw2
    Community Member
    6 Posts

    Re: Is User Registration Possible? Link to this post

    More clues here;


    and here (this link is at bottom of above post);

    this tutorial may be useful for you :

    Also, in one of the tutorials in suggests, if you want to just grab peoples details and not give them any 'logged in' capabilities, then don't register them (with a password) in the core members table.
    The Forum module is perfect for seeing how to extend the current member table, if you do need to do it tho.

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.