mirror of
https://github.com/silverstripe/silverstripe-blog
synced 2024-10-22 11:05:58 +02:00
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 {
|
||||
|
||||
/**
|
||||
* Extend the member table with some extra fields.
|
||||
*/
|
||||
function extraDBFields() {
|
||||
return array(
|
||||
'db' => array(
|
||||
@ -11,6 +14,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'
|
||||
));
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
?>
|
||||
|
@ -3,9 +3,8 @@
|
||||
class NewsletterSignupForm extends Form {
|
||||
|
||||
/**
|
||||
* Gets a NewsletterType which is associated with the BlogHolder, the
|
||||
* controller of this sign up form. It then uses the relationship getter
|
||||
* to find the Group of a NewsletterType.
|
||||
* Get the group code of the newsletter associated with the
|
||||
* BlogHolder instance that this form was created from.
|
||||
*/
|
||||
function get_group_code() {
|
||||
if($controller = $this->controller) {
|
||||
@ -17,18 +16,16 @@ class NewsletterSignupForm extends Form {
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Create the NewsletterSignupForm.
|
||||
* Take the fields and required fields from the extension role.
|
||||
*/
|
||||
function __construct($controller, $name) {
|
||||
$member = singleton('Member');
|
||||
|
||||
$fields = new FieldSet(
|
||||
new TextField('FirstName', 'Your first name'),
|
||||
new TextField('Surname', 'Your surname'),
|
||||
new EmailField('Email', 'Your email')
|
||||
);
|
||||
$fields = $member->subscribeFields();
|
||||
|
||||
$validator = new RequiredFields(array(
|
||||
'FirstName',
|
||||
'Email'
|
||||
));
|
||||
$validator = $member->subscribeRequiredFields();
|
||||
|
||||
$actions = new FieldSet(
|
||||
new FormAction('subscribe', 'Subscribe')
|
||||
@ -37,6 +34,14 @@ class NewsletterSignupForm extends Form {
|
||||
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) {
|
||||
$SQL_email = $data['Email'];
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user