Jump to:

10992 Posts in 2727 Topics by 1818 members

All other Modules

SilverStripe Forums » All other Modules » Newsletter module subscribe form problem

Discuss all other Modules here.

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

Page: 1
Go to End
Author Topic: 1132 Views
  • Mediaversa
    Avatar
    Community Member
    5 Posts

    Newsletter module subscribe form problem Link to this post

    Hello everyone,

    I'm new with SilverStripe and I have a problem with the newsletter module. I've made a subscribe form, but I cannot enable the field for the users email. The first and surname work flawless and the data entered in the form is submitted to the mailing list.

    In the backoffice, I cannot enable the field for the email, as the checkbox is disabled.

    Can anyone tell me what could cause this problem?

    Greetings

  • BlueO
    Avatar
    Community Member
    52 Posts

    Re: Newsletter module subscribe form problem Link to this post

    Hi there,

    I had trouble with the subscription page too so ended up patching one together form bits found on the forum/docs. It sits in /mysite/code/SignupPage.php

    hope it helps. The key thing is to set it to the right group in $defaultGroupID

    <?php

    class SignupPage extends Page {
       static $db = array(
       );
       static $has_one = array(
    );
    }

    class SignupPage_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 = 3;

       /**
       * This function lets you put a form on your page, using $Form.
       */
       function Form() {
          
          $fields = new FieldSet(

             // List your fields here
             new TextField("FirstName", "First name"),
             new TextField("Surname"),
             new EmailField("Email", "Email address")
          );
          
          $actions = new FieldSet(
             // List the action buttons here
             new FormAction("SignupAction", "Sign up")
          );
          
          $validator = new RequiredFields(
             "FirstName", "Email"
             // List the required fields here: "Email", "FirstName"
          );
          
          $form = new Form($this, "Form", $fields, $actions, $validator);
          
          //spam protection added - needs to be set in _config.php
          $protector = SpamProtectorManager::update_form($form, null, array('FirstName' => 'author_name', 'Email' => 'author_email',));
          if($protector) $protector->setFieldMapping('FirstName', 'Email');

       return $form;

       }

       /**
       * 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();
          $form->saveInto($member);

          // Write it to the database. This needs to happen before we add it to a group
          $member->write();

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

             $member->Groups()->add($group);
             // Redirect to a page in this case the home page
             Director::redirect('home/');

          }else{

             // Redirect to a failure page
             /* Director::redirect('failure/'); */

          }

       }
    }

    ?>

  • Mediaversa
    Avatar
    Community Member
    5 Posts

    Re: Newsletter module subscribe form problem Link to this post

    I've tried the thing above, but the result is a white page. When I remove $form from my template however, the page loads, but without the form (which is logical)

  • BlueO
    Avatar
    Community Member
    52 Posts

    Re: Newsletter module subscribe form problem Link to this post

    Hi, have you got the spamprotection module installed? If not you'll need to take that part out. It's running on ss 2.4 and the current newsletter release from silverstripe.org

    1132 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.