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 subscribe form problem


Go to End


4 Posts   1591 Views

Avatar
Mediaversa

Community Member, 5 Posts

28 May 2010 at 2:24am

Hello everyone,

I'm new with SilverStripe and I have a problem with the newsletter module. I've made a subscribe form, but I cannot enable the field for the users email. The first and surname work flawless and the data entered in the form is submitted to the mailing list.

In the backoffice, I cannot enable the field for the email, as the checkbox is disabled.

Can anyone tell me what could cause this problem?

Greetings

Avatar
BlueO

Community Member, 52 Posts

1 June 2010 at 10:17pm

Hi there,

I had trouble with the subscription page too so ended up patching one together form bits found on the forum/docs. It sits in /mysite/code/SignupPage.php

hope it helps. The key thing is to set it to the right group in $defaultGroupID

<?php

class SignupPage extends Page {
	static $db = array(
	);
	static $has_one = array(
   );
}
 
class SignupPage_Controller extends Page_Controller {
 
	// Make sure you set this to the right group.
	// See http://doc.silverstripe.com/doku.php?do=show&id=recipes%3Aforms
	private	 $defaultGroupID = 3;
 
	/**
	* This function lets you put a form on your page, using $Form.
	*/
	function Form() {
		
		$fields = new FieldSet(
 
			// List your fields here
			new TextField("FirstName", "First name"),
			new TextField("Surname"),
			new EmailField("Email", "Email address")
		); 
		
		$actions = new FieldSet(
			// List the action buttons here
			new FormAction("SignupAction", "Sign up")
		);
		
		$validator = new RequiredFields(
 			"FirstName", "Email"
			// List the required fields here: "Email", "FirstName"
		);
		
		$form = new Form($this, "Form", $fields, $actions, $validator);
		
		//spam protection added - needs to be set in _config.php
		$protector = SpamProtectorManager::update_form($form,  null, array('FirstName' => 'author_name', 'Email' => 'author_email',));
		if($protector) $protector->setFieldMapping('FirstName', 'Email');

	return $form;
  
	}
 
	/**
	* This function is called when the user submits the form.
	*/
	function SignupAction($data, $form) {
 
		// Create a new Member object and load the form data into it
		$member = new Member();
		$form->saveInto($member);
 
		// Write it to the database.  This needs to happen before we add it to a group
		$member->write();
 
		// Add the member to group. (Check if it exists first)
		if($group = DataObject::get_one('Group', "ID = $this->defaultGroupID")) { 
 
			$member->Groups()->add($group);
			// Redirect to a page in this case the home page
			Director::redirect('home/');
 
		}else{
 
			// Redirect to a failure page
			/* Director::redirect('failure/'); */
 
		}
 
	}
}

?>

Avatar
Mediaversa

Community Member, 5 Posts

2 June 2010 at 12:09am

I've tried the thing above, but the result is a white page. When I remove $form from my template however, the page loads, but without the form (which is logical)

Avatar
BlueO

Community Member, 52 Posts

2 June 2010 at 10:24am

Hi, have you got the spamprotection module installed? If not you'll need to take that part out. It's running on ss 2.4 and the current newsletter release from silverstripe.org