Abstracted fields onto BlogRole from subscribe form, added some documentation about what it does
This commit is contained in:
parent
d971db30d0
commit
fe23b0cef9
|
@ -2,6 +2,9 @@
|
||||||
|
|
||||||
class BlogRole extends DataObjectDecorator {
|
class BlogRole extends DataObjectDecorator {
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Extend the member table with some extra fields.
|
||||||
|
*/
|
||||||
function extraDBFields() {
|
function extraDBFields() {
|
||||||
return array(
|
return array(
|
||||||
'db' => array(
|
'db' => array(
|
||||||
|
@ -10,6 +13,27 @@ class BlogRole extends DataObjectDecorator {
|
||||||
),
|
),
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* These fields are used for the newsletter subscription form.
|
||||||
|
*/
|
||||||
|
function subscribeFields() {
|
||||||
|
return new FieldSet(
|
||||||
|
new TextField('FirstName', 'Your first name'),
|
||||||
|
new TextField('Surname', 'Your surname'),
|
||||||
|
new EmailField('Email', 'Your email')
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* These are the required fields for the newsletter subscription form.
|
||||||
|
*/
|
||||||
|
function subscribeRequiredFields() {
|
||||||
|
return new RequiredFields(array(
|
||||||
|
'FirstName',
|
||||||
|
'Email'
|
||||||
|
));
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -12,7 +12,7 @@ class ConfirmNewsletterSignup extends Controller {
|
||||||
Requirements::themedCSS('typography');
|
Requirements::themedCSS('typography');
|
||||||
Requirements::themedCSS('form');
|
Requirements::themedCSS('form');
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Action for signing up a member to a given group in NewsletterSignupForm.
|
* Action for signing up a member to a given group in NewsletterSignupForm.
|
||||||
* Used as mysite.com/confirm-subscription/member/123 (where 123 is a md5 hash to find the member)
|
* Used as mysite.com/confirm-subscription/member/123 (where 123 is a md5 hash to find the member)
|
||||||
|
|
|
@ -3,9 +3,8 @@
|
||||||
class NewsletterSignupForm extends Form {
|
class NewsletterSignupForm extends Form {
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Gets a NewsletterType which is associated with the BlogHolder, the
|
* Get the group code of the newsletter associated with the
|
||||||
* controller of this sign up form. It then uses the relationship getter
|
* BlogHolder instance that this form was created from.
|
||||||
* to find the Group of a NewsletterType.
|
|
||||||
*/
|
*/
|
||||||
function get_group_code() {
|
function get_group_code() {
|
||||||
if($controller = $this->controller) {
|
if($controller = $this->controller) {
|
||||||
|
@ -17,26 +16,32 @@ class NewsletterSignupForm extends Form {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Create the NewsletterSignupForm.
|
||||||
|
* Take the fields and required fields from the extension role.
|
||||||
|
*/
|
||||||
function __construct($controller, $name) {
|
function __construct($controller, $name) {
|
||||||
|
$member = singleton('Member');
|
||||||
|
|
||||||
|
$fields = $member->subscribeFields();
|
||||||
|
|
||||||
|
$validator = $member->subscribeRequiredFields();
|
||||||
|
|
||||||
$fields = new FieldSet(
|
|
||||||
new TextField('FirstName', 'Your first name'),
|
|
||||||
new TextField('Surname', 'Your surname'),
|
|
||||||
new EmailField('Email', 'Your email')
|
|
||||||
);
|
|
||||||
|
|
||||||
$validator = new RequiredFields(array(
|
|
||||||
'FirstName',
|
|
||||||
'Email'
|
|
||||||
));
|
|
||||||
|
|
||||||
$actions = new FieldSet(
|
$actions = new FieldSet(
|
||||||
new FormAction('subscribe', 'Subscribe')
|
new FormAction('subscribe', 'Subscribe')
|
||||||
);
|
);
|
||||||
|
|
||||||
parent::__construct($controller, $name, $fields, $actions, $validator);
|
parent::__construct($controller, $name, $fields, $actions, $validator);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* NewsletterSignupForm action.
|
||||||
|
* Requires that the email address be submitted in the form.
|
||||||
|
*
|
||||||
|
* Checks if there is a member in the system by submitted email, and checks if
|
||||||
|
* that member has already signed up. If member has, then form gives message and
|
||||||
|
* redirects back. If not, then it carries on with the process.
|
||||||
|
*/
|
||||||
function subscribe($data, $form) {
|
function subscribe($data, $form) {
|
||||||
$SQL_email = $data['Email'];
|
$SQL_email = $data['Email'];
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue