renderWith(array( $this->class, 'Form' )); } function CreateAccount($data, $form) { //Check for existing member email address if ($member = Member::get()->filter('Email',Convert::raw2sql($data['Email']))->first() ) { //Set error message $form->AddErrorMessage('Email', "Sorry, that email address already exists. Please choose another or login with that email.", 'bad'); //Set form data from submitted values Session::set("FormInfo.Form_CallForSpeakersRegistrationForm.data", $data); //Return back to form return Controller::curr()->redirectBack(); } //Otherwise create new member and log them in $Member = new Member(); $form->saveInto($Member); $Member->write(); $Member->login(); //Find or create the 'user' group if (!$userGroup = Group::get()->filter('Code', 'site-accounts')->first()) { $userGroup = new Group(); $userGroup->Code = "site-accounts"; $userGroup->Title = "Site Accounts"; $userGroup->Write(); $Member->Groups()->add($userGroup); } //Add member to user group $Member->Groups()->add($userGroup); return Controller::curr()->redirect($form->controller->Link()); } }