Skip to main content

This site requires you to update your browser. Your browsing experience maybe affected by not having the most up to date version.

We're retiring the forums!

The SilverStripe forums have passed their heyday. They'll stick around, but will be read only. We'd encourage you to get involved in the community via the following channels instead:

All other Modules /

Discuss all other Modules here.

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

Newsletter module: Widget for subscription form

Go to End

3 Posts   1940 Views


Community Member, 5 Posts

19 October 2010 at 1:14am


I'm running SS 2.4.2 and have installed the newsletter module.
I have setup a newsletter subscription page type just containing an email field so that users can register easily.
What I'd like to do though is make this form appear as a widget so I can insert it in the sidebar of my home page (which has already been setup to display widgets).

How do I do this?

I tried using the page content and single page widgets in the hope that they would simply display the form content from my subscription page within the widget, however it seems that these widgets assume a normal sitetree page type and will only output the 'content' field rather than the form.

Are there any other ways round this? Am I missing an obvious solution?

Any help will be much appreciated.


Forum Moderator, 1899 Posts

19 October 2010 at 9:20pm

Hi, How's this...



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(

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

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

		// 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 = 'Newsletter'"))

		// Redirect to a page thanking people for registering, this needs creating int he CMS




Community Member, 5 Posts

20 October 2010 at 3:10am

Hi Swaiba

That's great, thanks! Works a treat.
I'm still quite new to SS, so am still getting my head around the way things work, but this has been a big help in more ways than one.

Thanks again.