how about this...
mysite\widgets\NewsletterSignUpWidget.php
<?php
class NewsletterSignUpWidget extends Widget{
static $title = "";
static $cmsTitle = "Newsletter Sign Up";
static $description = "Newsletter Sign Up - requires page with URL segement 'thanks-for-joining' in the CMS";
}
class NewsletterSignUpWidget_Controller extends Widget_Controller {
function NewsletterSignUpForm() {
$fields = new FieldSet(
new TextField("FirstName", "Enter your first name: ", ""),
new EmailField("Email", "Enter your email address: ", "")
);
$actions = new FieldSet(
new FormAction("doform", "Subscribe")
);
$required =new RequiredFields(
"FirstName",
"Email"
);
return new Form($this, "dosignupform", $fields, $actions, $required);
}
function dosignupform($data) {
$member = new Member();
$member->FirstName = $data['FirstName'];
$member->Email = $data['Email'];
$member->write();
if($group = DataObject::get_one('Group', "Code = 'Newsletter'")){
$member->Groups()->add($group);
}
// Redirect to a page thanking people for registering, this needs creating int he CMS
Director::redirect('/thanks-for-joining');
}
}
mysite\widgets\NewsletterSignUpWidget.ss
$NewsletterSignUpForm