Abstracted fields onto BlogRole from subscribe form, added some documentation about what it does

This commit is contained in:
Sean Harvey 2007-12-20 04:32:01 +00:00
parent d971db30d0
commit fe23b0cef9
3 changed files with 46 additions and 17 deletions

View File

@ -2,6 +2,9 @@
class BlogRole extends DataObjectDecorator {
/**
* Extend the member table with some extra fields.
*/
function extraDBFields() {
return 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'
));
}
}

View File

@ -12,7 +12,7 @@ class ConfirmNewsletterSignup extends Controller {
Requirements::themedCSS('typography');
Requirements::themedCSS('form');
}
/**
* 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)

View File

@ -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,26 +16,32 @@ 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 = $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(
new FormAction('subscribe', 'Subscribe')
);
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'];