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 Module


Go to End


18 Posts   4653 Views

Avatar
ocean

Community Member, 37 Posts

17 January 2012 at 6:24am

Howdy,

Trying a number of ways to get unsubscribe to work with current setup of Newsletter (installation as above) and having no luck, just the following response:

"Sorry, your don't appear to be in any of our mailing lists."

Anyone familiar with this issue, and even better, how to solve it?

Its just a plain install of the module, not altered anything yet.

Best wishes
~ Sean

Avatar
ocean

Community Member, 37 Posts

21 January 2012 at 12:41am

Fixed!

Newsletter mod appears to be working perfectly...

My own fabulously stupid blunder : ) I overlooked setting a mailing list group in "newsletter settings" tab, hopefully this note will help a few avoid that error.

Now of course subscriptions and unsubscribes are operating as one would expect, and also newsletters are posting to the groups selected, testing very well so far, many thanks Normann and Sam for developing this, now I can get to focusing on developing an audience for my music.

Warmly
~ Sean

Avatar
benni91

Community Member, 72 Posts

9 February 2012 at 12:29pm

Hi,
@ first THHHXX !! :) Your post helped me a lot :)

Do you also know how to add an simple Subscription Form ? Just an button and a textfield for the Email ?

Regards
Benni

Avatar
Rossel

Community Member, 18 Posts

9 February 2012 at 4:54pm

Edited: 09/02/2012 10:17pm

@benni91
This is what i have, its likely a bit more than what your after, but it might help.

In my Page Controller:

	function SubscribeForm() {
		$email ='';
		$newsletter_group = DataObject::get_one('Group', "ID = 4");
		$member = $this->CurrentMember();
		if($member):
			$email = $member->Email; 
		endif;
		if(!$member || !$member->inGroup($newsletter_group)):
			// Create Fields
			$fields = new FieldSet(new EmailField('Email','Email', $email,'100'));
			// Create Action
			$actions = new FieldSet(new FormAction('doSubscribeForm', 'Go'));
			// Create Validators
			$validator = new RequiredFields('Email');
			//Create Form
			$form = new Form($this, 'SubscribeForm', $fields, $actions, $validator );

			return $form;
		endif;
		}

	function doSubscribeForm($data, $form){
		$email = Convert::raw2sql($data['Email']); // prevent sql injection
		$existing_member = DataObject::get_one("Member", "Email = '$email'");
		
		if($member = $this->CurrentMember()):
			// Get member with matching email.
			// If logged in user matches that member add them to newsletter group.
			if($member->ID == $existing_member->ID):
				$newsletter_group = DataObject::get_one('Group', "ID = 4");
				$existing_member->Groups()->add($newsletter_group);
			endif;
			return Director::redirectBack();
		else:
			if($existing_member):
				return Director::redirect(Director::BaseURL() . 'Security/login');
			else:
				return Director::redirect($this->Link("/sign-up/?s=1&e=" . $email));
			endif;
		endif;
		}

Template:

				<div class="SubscribeForm">
					<% if SubscribeForm %>
					$SubscribeForm
					<% else %>
					<div> You've subscribed! </div>
					<% end_if %>
				</div>

Avatar
benni91

Community Member, 72 Posts

9 February 2012 at 10:09pm

Edited: 09/02/2012 10:11pm

Hi,
thx for the code - I added the first part to Sidebar.php (Write file? Or is it necessary to add the code somewhere in the newsletter module?)

and the template code to Newsletter.ss

<% control getPageByClass(Sidebar) %>
     <div class="SubscribeForm">
          <% if SubscribeForm %>
               $SubscribeForm
               <% else %>
               <div style="padding:8px 20px 11px 20px; height:16px;"> You've subscribed! </div>
          <% end_if %>
     </div>
<% end_control %>

but the Problem is, it shows only the text "You've subscribed! " Doesnt matter if logged in or not :/ there's no form.
What should i do?

Avatar
Rossel

Community Member, 18 Posts

9 February 2012 at 10:29pm

You'll have to make sure your mailing list group exists and that the group ID is correct:

$newsletter_group = DataObject::get_one('Group', "ID = 4"); 

Maybe try putting the form functions in your Page.php Controller, this is important if you want it to be displayed on more than one page.
If there is no form found/returned it will display the message, so I'm guessing its not finding it atm.

Sorry Its not written that well, I'm new to Silverstripe!

Avatar
benni91

Community Member, 72 Posts

10 February 2012 at 2:26am

Sry i didn't get it :/

The group id has to fit to the id of one group i created in the Security section?
I created a group there called "newsletter subscriber" it's the third group => ID 3? (Doesn't Work)

If someone wants to subscribe, do he need an account?!
Ahhh What should i do :D Help ! :D
Sry i'm not so good at this

With
<% control getPageByClass(Sidebar) %>
i'm controlling everything on the Sidebar Page. Doesn't matter on which site you are.

Avatar
benni91

Community Member, 72 Posts

12 February 2012 at 11:57am

Edited: 12/02/2012 12:03pm

You were right.
After putting it into the page.php controller it shows me the form.
but after clicking go i receive an error "Page not found"

and now? :/

another problem is: the jquery imageslider stopped working after adding your codes. i think this is a problem of the page_controller
cause i had this problem on another site too, after adding a contact form code to the page_controller. do someone know how to solve it?