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've moved the forum!

Please use forum.silverstripe.org for any new questions (announcement).
The forum archive will stick around, but will be read only.

You can also use our Slack channel or StackOverflow to ask for help.
Check out our community overview for more options to contribute.

All other Modules /

Discuss all other Modules here.

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

Newsletter subscription field - able to place anywhere?


Go to End


3 Posts   1274 Views

Avatar
Ryan M.

Community Member, 309 Posts

2 February 2011 at 4:41pm

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??

Avatar
Ryan M.

Community Member, 309 Posts

2 February 2011 at 6:32pm

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.

Avatar
swaiba

Forum Moderator, 1899 Posts

3 February 2011 at 1:39am

Edited: 03/02/2011 1:40am

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