Pastie now auto-senses if line-wrap is a bad or good idea. Feedback?
## mark a section (Learn more)
<?php class ClientForms extends Page { static $db = array( 'AccessMyAccountTitle' => 'Varchar(255)', 'AccessMyAccountText' => 'HTMLText', 'MyAccountTitle' => 'Varchar(255)', 'MyAccountText' => 'HTMLText', "AccountThanksTitle" => "Varchar", "AccountThanksContent" => "HTMLText", "ErrorTitle" => "Varchar", "ErrorContent" => "HTMLText", ); function getCMSFields() { $fields = parent::getCMSFields(); $fields->addFieldToTab("Root.Content.Main", new TextField("AccessMyAccountTitle", "Title for not logged Users")); $fields->addFieldToTab("Root.Content.Main", new HTMLEditorField("AccessMyAccountText", "Content for not Logged Users")); $fields->addFieldToTab("Root.Content.Main", new TextField("MyAccountTitle", "'My account' Title")); $fields->addFieldToTab("Root.Content.Main", new HTMLEditorField("MyAccountText", "'My account' text")); $fields->addFieldsToTab("Root.Content.Thanks", array( new TextField("ThanksTitle", "Title"), new HTMLEditorField("ThanksContent", "Content") )); $fields->addFieldsToTab("Root.Content.Error", array( new TextField("ErrorTitle", "Title"), new HTMLEditorField("ErrorContent", "Content") )); $fields->removeFieldFromTab("Root.Content.Main","Content"); $fields->removeFieldFromTab("Root.Content.Main","Title"); $fields->removeFieldFromTab("Root.Content.Main","MenuTitle"); return $fields; } //remember to change the default group ID function SignupForm(){ return new Form($this, "Form", new FieldSet( // List your fields here new TextField("FirstName", "First name"), new TextField("Surname"), new EmailField("Email", "Email address") ), new FieldSet( // List the action buttons here new FormAction("SignupAction", "Sign up") ), new RequiredFields( "Email", "FirstName" ) ); } function SignupAction($data, $form) { if($member = DataObject::get_one("Member", "`Email` = '". Convert::raw2sql($data['Email']) . "'")) { if($member) { $form->addErrorMessage("Blurb", _t('ForumMemberProfile.EMAILEXISTS','Sorry, that email address already exists. Please choose another.'), "bad"); // Load errors into session and post back Session::set("FormInfo.Form_RegistrationForm.data", $data); Director::redirectBack(); return; } } // Create a new Member object and load the form data into it $member = new Member(); $form->saveInto($member); // Write it to the database. This needs to happen before we add it to a group $member->write(); $member->login(); // Add the member to group. (Check if it exists first) if($group = DataObject::get_one('Group', "Code = 'clients'")) { $member->Groups()->add($group); // Redirect to a page thanking people for registering Director::redirect($this->Link() . 'thanks'); }else{ // Redirect to a failure page Director::redirect($this->Link() . 'error'); } } function thanks() { return array( 'Title' => $this->ThanksTitle, 'Content' => $this->ThanksContent, 'Form' => ' ', ); } function error() { return array( 'Title' => $this->ErrorTitle, 'Content' => $this->ErrorContent, 'Form' => ' ', ); } } class ClientForms_Controller extends Page_Controller{ function Form(){ if($url = Director::urlparam('Form')){ Session::set('formToLoad', $url); }else{ Session::clear("formToLoad"); } $var = Session::get('formToLoad'); if (isset($var)) { $fields = singleton('Member')->$var(); $actions = new FieldSet(new FormAction("SaveFields", "Update my information")); $form = new Form($this, "Form", $fields, $actions); $form->loadDataFrom(Member::currentUser()); return array('Form' => $form); } } function SaveFields($data, $form){ $member = Member::currentUser(); $form->saveInto($member); $member->write(); Director::redirect('my-account-home/'); Session::clear("formToLoad"); } } ?>
This paste will be private.
From the Design Piracy series on my blog: