Jump to:

1385 Posts in 493 Topics by 522 members


SilverStripe Forums » Themes » Losing connection to controller with renderWith()

Discuss SilverStripe Themes.

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

Page: 1
Go to End
Author Topic: 1267 Views
  • sonet
    Community Member
    33 Posts

    Losing connection to controller with renderWith() Link to this post

    I want to add simple, custom control (newsletter signup form, which is being rendered with a custom form template). In code below, when returning $formSignup only, everything works fine. When using the renderWith() method the proper action (/home/SignupForm in URL) is being called, but somehow the connection to the page controller is lost. I am not sure what I am doing wrong. The custom form is being send to the browser only completely detached.

       * This function puts a form on your page, using $Form.
       public function SignupForm() {
          $formSignup = new Form($this, "SignupForm", new FieldSet(
                new EmailField("Email", "","E-Mail Address")),
                new FieldSet(new FormAction("SignupAction", "Sign up"))//,
                //new RequiredFields("Email")
          //return $formSignup;
          return $this->customise($formSignup)->renderWith(array('FormSignup'));

       * This function is called when the user submits the form.
       public 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 = $this->defaultGroupID")) {

             // Redirect to a page thanking people for registering
          } else {
             // Redirect to a failure page

    I appreciate any help.

  • sonet
    Community Member
    33 Posts
  • CHD
    Community Member
    218 Posts

    Re: Losing connection to controller with renderWith() Link to this post

    this may come in handy for anybody who wants to easily include forms in a sidebar or any other area of the site, without controlling a hidden page:


    it also has an easy "query database for existing member" function that isn't covered in the form tutorials...

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.