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.

All other Modules

Discuss all other Modules here.

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

Newsletter Module subscription page/process adding users and extending basic functionality a little, need help


Reply

1259 Views

Avatar
TF-35Lightning

29 September 2010 at 4:59pm (Last edited: 29 September 2010 5:02pm), Community Member, 137 Posts

Hi guys,
I am trying to do a few things to the Newsletter Module sign up process and as this module isnt kept up to date before and I don't have that much knowledge of Silverstripe I have found this very difficult, and have gone off what is being discussed in these threads:
http://www.silverstripe.org/all-other-modules/show/270155?start=16
http://www.silverstripe.org/template-questions/show/290674#post290674
http://www.silverstripe.org/all-other-modules/show/290583?start=0#post290680#post290680

All I want to do is.
1. When user enter email address into subscription form their email is added to members table and appropriate group for mailing list (which is currently working)

2. At the same time I want 2 new fields for this record, 1: to hold a randomly generated number 2: to have another field hold what the status is for this user (eg at the moment they in the table but they are unconfirmed because they havent clicked a link in the email I am about to send them )

3. Send the user an email with a confirmation link that holds a link to the page where this checking will be done and obviously it needs to be something like mysite/mailinglist?email=theuser@theiraddress&randomnumber=3geg23r3wrf23f

4. I then check to make sure the records email and randomnumber is the same before replacing my (unconfirmed, with confirmed)

Here is what I have for step 1 which works, but as I mentioned I am a bit at a loss at how to do these other few steps and are hoping someone out there might be able to help me through it. Any help would be great

Step 1: (user is added to membertable and appropriate group)

<?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 SignUpForm() {
$fields = new FieldSet(
      
// List your fields here
new TextField("FirstName", "First name"),
new TextField("Surname"),
new EmailField("Email", "address"),       
);

$actions = new FieldSet(
new FormAction("SignupAction", "Sign up")
);

$validator = new RequiredFields(
"FirstName", "Surnname", "Email"       
// List the required fields here: "Email", "FirstName"
);

$form = new Form($this, "SignUpForm", $fields, $actions, $validator);
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/'); */

}

}
}

?>