Jump to:

10931 Posts in 2614 Topics by 1810 members

All other Modules

SilverStripe Forums » All other Modules » Newsletter subscription field - able to place anywhere?

Discuss all other Modules here.

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

Page: 1
Go to End
Author Topic: 884 Views
  • Ryan M.
    Avatar
    Community Member
    309 Posts

    Newsletter subscription field - able to place anywhere? Link to this post

    I'm wondering how to create a fieldset that is simply a box for an email address and a submit button, that connects to the newsletter module, which I can place anywhere in my templates, such as $SubscriptionForm. I want to use the newsletter module, but without using the userdefinedform newsletter page type.

    Ideas??

  • Ryan M.
    Avatar
    Community Member
    309 Posts

    Re: Newsletter subscription field - able to place anywhere? Link to this post

    I thought of a way around this but it seems to be more effort than its worth so I'd still like to hear from anyone if they have any better suggestions.

    The idea I have is to just create a dataobject for the signups, store the email address in the object, and set up a tablelistfield in the admin so I can export the addresses to CSV, and import into the newsletter mailing list. This sounds like it'd work in theory, the only bad thing is it's labor intensive and I'd have to repeat the process every time I want to get an updated list of email addresses.

  • swaiba
    Avatar
    Forum Moderator
    1786 Posts

    Re: Newsletter subscription field - able to place anywhere? Link to this post

    how about this...

    mysite\widgets\NewsletterSignUpWidget.php

    <?php
    class NewsletterSignUpWidget extends Widget{
       static $title = "";
       static $cmsTitle = "Newsletter Sign Up";
       static $description = "Newsletter Sign Up - requires page with URL segement 'thanks-for-joining' in the CMS";
    }

    class NewsletterSignUpWidget_Controller extends Widget_Controller {
       function NewsletterSignUpForm() {
          $fields = new FieldSet(
             new TextField("FirstName", "Enter your first name: ", ""),
             new EmailField("Email", "Enter your email address: ", "")
          );

          $actions = new FieldSet(
             new FormAction("doform", "Subscribe")
          );

          $required =new RequiredFields(
             "FirstName",
             "Email"
          );

          return new Form($this, "dosignupform", $fields, $actions, $required);
       }

       function dosignupform($data) {
          $member = new Member();
          $member->FirstName = $data['FirstName'];
          $member->Email = $data['Email'];
          $member->write();

          if($group = DataObject::get_one('Group', "Code = 'Newsletter'")){
             $member->Groups()->add($group);
          }

          // Redirect to a page thanking people for registering, this needs creating int he CMS
          Director::redirect('/thanks-for-joining');
       }
    }

    mysite\widgets\NewsletterSignUpWidget.ss

    $NewsletterSignUpForm

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