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/'); */
}
}
}
?>