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.

Archive /

Our old forums are still available as a read-only archive.

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

newsletter signup form


Go to End


1392 Views

Avatar
grilldan

Community Member, 135 Posts

1 September 2008 at 3:12pm

Edited: 01/09/2008 6:46pm

*update4* SOLVED
in SugnupForm.php, changed

	$groups = $member->Groups();
		$groups->setByCheckboxes(array("newslettersubscribe"), $data);

to

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

*update3*
I need some way to get Member id and add it to the Gourp_Member table when people register for the newsletter.

*update 2*
When I add a member manually from the newsletter tab in the admin panel, the row is added to the member table, in the same format...

*update*
I figured out that it is writing to the "Member" table in the database. Is there a way for the news letter to automatically add members from the Member list?

------------------

I followed the guide here:
http://doc.silverstripe.com/doku.php?id=recipes:simplesignupform

(I see the note saying its outdated.)

What could be done to make this work? The only problem I have is that it isn't adding anything to the database.

here is what I have:

SignupForm.php

<?php
class SignupForm extends Form {	
	function signup($data,$form) {
		// Create a new member using the data from the form
		// TODO: needs validation - all fields filled out, email doesn't exist already etc
		$member = new Member($data);
		$member->write();
		
		// Add the new member to the 'newslettersubscribe' group
		$groups = $member->Groups();
		$groups->setByCheckboxes(array("newslettersubscribe"), $data);
		
		// Write the Member table row
		$member->write();
		
		Director::redirect('/sign-up-complete/');
	}
}	
?>

SignupPage.php

<?php
class SignupPage extends Page {
}
 
class SignupPage_Controller extends Page_Controller {
	function AfterContent() {
		// This is a dirty hack, suggestions?
		// It returns early if we're on the thanks page - we don't want the form on that page
		if($this->urlParams[Action] == 'thanks') return;
		
		return new SignupForm($this, "AfterContent", 
			new FieldSet(
				new TextField("FirstName", "First Name:"),
				new TextField("Surname", "Surname:"),
				new TextField("Email", "Email:")
				
			), 
			new FieldSet(
				new FormAction("signup", "Subscribe")
 
			), 
			new RequiredFields(
				"FirstName",
				"Surname",
				"Email"
			));
	}
}
?>

I have a newsletter named newslettersubscribe. I made it from the newsletter tab of the admin panel.

I know there is a "subscribe form" page type, but I don't want the users to need to use a checkbox for selecting the news group.

Is there a way to set a "default" news group maybe?