diff --git a/code/BlogRole.php b/code/BlogRole.php index 8e7cc4d..a22ba17 100755 --- a/code/BlogRole.php +++ b/code/BlogRole.php @@ -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' + )); + } } diff --git a/code/ConfirmNewsletterSignup.php b/code/ConfirmNewsletterSignup.php index cb1adb6..da3f86f 100755 --- a/code/ConfirmNewsletterSignup.php +++ b/code/ConfirmNewsletterSignup.php @@ -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) diff --git a/code/NewsletterSignupForm.php b/code/NewsletterSignupForm.php index 48ca29a..961120c 100755 --- a/code/NewsletterSignupForm.php +++ b/code/NewsletterSignupForm.php @@ -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'];