Jump to:

5537 Posts in 1737 Topics by 1223 members

Customising the CMS

SilverStripe Forums » Customising the CMS » Newsletter signup form widget

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

Page: 1
Go to End
Author Topic: 2897 Views
  • Phill
    Community Member
    75 Posts

    Newsletter signup form widget Link to this post


    Im trying to build a widget which allows people to sign up to a newsletter iv been able to build a form which does this on a page but cant get it to work as a widget.

    This is the code iv been using to generate the form on a page which all works fine

    function NewsletterForm() {
    return new Form($this, "FormJoin", new FieldSet(
    // List the your fields here
    new EmailField("Email", "Enter your email address: ", "")

    ), new FieldSet(
    // List the action buttons here
    new FormAction("doform", "Subscribe")

    ), new RequiredFields(
    function doform($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', "Code = 'mailing-list'")) {

    // Redirect to a page thanking people for registering

    but i cant work out how to do the same for a widget it doesnt work if i put the code in the widgets file and i cant access it from the widget if its stored in page.php any ideas on how i could do this?


  • rokryan
    Community Member
    13 Posts

    Re: Newsletter signup form widget Link to this post

    I'm in the same boat, does anyone have a stable solution for a Newsletter Subscription Widget??

  • CHD
    Community Member
    218 Posts

    Re: Newsletter signup form widget 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.