/** * Return a {@link Form} instance allowing a user to * add links in the TinyMCE content editor. * * @return Form */ public function LinkForm() { $siteTree = TreeDropdownField::create('internal', _t('HTMLEditorField.PAGE', "Page"), 'SilverStripe\\CMS\\Model\\SiteTree', 'ID', 'MenuTitle', true); // mimic the SiteTree::getMenuTitle(), which is bypassed when the search is performed $siteTree->setSearchFunction(array($this, 'siteTreeSearchCallback')); $numericLabelTmpl = '<span class="step-label"><span class="flyout">Step %d.</span>' . '<span class="title">%s</span></span>'; $form = new Form($this->controller, "{$this->name}/LinkForm", new FieldList($headerWrap = new CompositeField(new LiteralField('Heading', sprintf('<h3 class="htmleditorfield-mediaform-heading insert">%s</h3>', _t('HTMLEditorField.LINK', 'Insert Link')))), $contentComposite = new CompositeField(OptionsetField::create('LinkType', DBField::create_field('HTMLFragment', sprintf($numericLabelTmpl, '1', _t('HTMLEditorField.LINKTO', 'Link type'))), array('internal' => _t('HTMLEditorField.LINKINTERNAL', 'Link to a page on this site'), 'external' => _t('HTMLEditorField.LINKEXTERNAL', 'Link to another website'), 'anchor' => _t('HTMLEditorField.LINKANCHOR', 'Link to an anchor on this page'), 'email' => _t('HTMLEditorField.LINKEMAIL', 'Link to an email address'), 'file' => _t('HTMLEditorField.LINKFILE', 'Link to download a file')), 'internal'), LiteralField::create('Step2', '<div class="step2">' . sprintf($numericLabelTmpl, '2', _t('HTMLEditorField.LINKDETAILS', 'Link details')) . '</div>'), $siteTree, TextField::create('external', _t('HTMLEditorField.URL', 'URL'), 'http://'), EmailField::create('email', _t('HTMLEditorField.EMAIL', 'Email address')), $fileField = UploadField::create('file', _t('HTMLEditorField.FILE', 'SilverStripe\\Assets\\File')), TextField::create('Anchor', _t('HTMLEditorField.ANCHORVALUE', 'Anchor')), TextField::create('Subject', _t('HTMLEditorField.SUBJECT', 'Email subject')), TextField::create('Description', _t('HTMLEditorField.LINKDESCR', 'Link description')), CheckboxField::create('TargetBlank', _t('HTMLEditorField.LINKOPENNEWWIN', 'Open link in a new window?')), HiddenField::create('Locale', null, $this->controller->Locale))), new FieldList()); $headerWrap->setName('HeaderWrap'); $headerWrap->addExtraClass('CompositeField composite cms-content-header form-group--no-label '); $contentComposite->setName('ContentBody'); $contentComposite->addExtraClass('ss-insert-link content'); $fileField->setAllowedMaxFileNumber(1); $form->unsetValidator(); $form->loadDataFrom($this); $form->addExtraClass('htmleditorfield-form htmleditorfield-linkform cms-mediaform-content'); $this->extend('updateLinkForm', $form); return $form; }
public function __construct(Controller $controller, $name) { // Set default fields $fields = new FieldList(HiddenField::create("AuthenticationMethod", null, $this->authenticator_class, $this), HiddenField::create('tempid', null, $controller->getRequest()->requestVar('tempid')), PasswordField::create("Password", _t('Member.PASSWORD', 'Password')), LiteralField::create('forgotPassword', sprintf('<p id="ForgotPassword"><a href="%s" target="_top">%s</a></p>', $this->getExternalLink('lostpassword'), _t('CMSMemberLoginForm.BUTTONFORGOTPASSWORD', "Forgot password?")))); if (Security::config()->autologin_enabled) { $fields->push(CheckboxField::create("Remember", _t('Member.REMEMBERME', "Remember me next time?"))); } // Determine returnurl to redirect to parent page $logoutLink = $this->getExternalLink('logout'); if ($returnURL = $controller->getRequest()->requestVar('BackURL')) { $logoutLink = Controller::join_links($logoutLink, '?BackURL=' . urlencode($returnURL)); } // Make actions $actions = new FieldList(FormAction::create('dologin', _t('CMSMemberLoginForm.BUTTONLOGIN', "Log back in")), LiteralField::create('doLogout', sprintf('<p id="doLogout"><a href="%s" target="_top">%s</a></p>', $logoutLink, _t('CMSMemberLoginForm.BUTTONLOGOUT', "Log out")))); parent::__construct($controller, $name, $fields, $actions); }
public function testValidation() { $field = CheckboxField::create('Test', 'Testing'); $validator = new RequiredFields(); $field->setValue(1); $this->assertTrue($field->validate($validator), 'Field correctly validates integers as allowed'); //string value should validate $field->setValue("test"); $this->assertTrue($field->validate($validator), 'Field correctly validates words as allowed'); //empty string should validate $field->setValue(''); $this->assertTrue($field->validate($validator), 'Field correctly validates empty strings as allowed'); //null should validate $field->setValue(null); $this->assertTrue($field->validate($validator), 'Field correct validates null as allowed'); }
/** * Constructor * * @skipUpgrade * @param Controller $controller The parent controller, necessary to * create the appropriate form action tag. * @param string $name The method on the controller that will return this * form object. * @param FieldList $fields All of the fields in the form - a * {@link FieldList} of {@link FormField} * objects. * @param FieldList|FormAction $actions All of the action buttons in the * form - a {@link FieldList} of * {@link FormAction} objects * @param bool $checkCurrentUser If set to TRUE, it will be checked if a * the user is currently logged in, and if * so, only a logout button will be rendered */ public function __construct($controller, $name, $fields = null, $actions = null, $checkCurrentUser = true) { // This is now set on the class directly to make it easier to create subclasses // $this->authenticator_class = $authenticatorClassName; $customCSS = project() . '/css/member_login.css'; if (Director::fileExists($customCSS)) { Requirements::css($customCSS); } if (isset($_REQUEST['BackURL'])) { $backURL = $_REQUEST['BackURL']; } else { $backURL = Session::get('BackURL'); } if ($checkCurrentUser && Member::currentUser() && Member::logged_in_session_exists()) { $fields = FieldList::create(HiddenField::create("AuthenticationMethod", null, $this->authenticator_class, $this)); $actions = FieldList::create(FormAction::create("logout", _t('Member.BUTTONLOGINOTHER', "Log in as someone else"))); } else { if (!$fields) { $label = Member::singleton()->fieldLabel(Member::config()->unique_identifier_field); $fields = FieldList::create(HiddenField::create("AuthenticationMethod", null, $this->authenticator_class, $this), $emailField = TextField::create("Email", $label, null, null, $this), PasswordField::create("Password", _t('Member.PASSWORD', 'Password'))); if (Security::config()->remember_username) { $emailField->setValue(Session::get('SessionForms.MemberLoginForm.Email')); } else { // Some browsers won't respect this attribute unless it's added to the form $this->setAttribute('autocomplete', 'off'); $emailField->setAttribute('autocomplete', 'off'); } if (Security::config()->autologin_enabled) { $fields->push(CheckboxField::create("Remember", _t('Member.KEEPMESIGNEDIN', "Keep me signed in"))->setAttribute('title', sprintf(_t('Member.REMEMBERME', "Remember me next time? (for %d days on this device)"), RememberLoginHash::config()->get('token_expiry_days')))); } } if (!$actions) { $actions = FieldList::create(FormAction::create('dologin', _t('Member.BUTTONLOGIN', "Log in")), LiteralField::create('forgotPassword', '<p id="ForgotPassword"><a href="' . Security::lost_password_url() . '">' . _t('Member.BUTTONLOSTPASSWORD', "I've lost my password") . '</a></p>')); } } if (isset($backURL)) { $fields->push(HiddenField::create('BackURL', 'BackURL', $backURL)); } // Reduce attack surface by enforcing POST requests $this->setFormMethod('POST', true); parent::__construct($controller, $name, $fields, $actions); $this->setValidator(RequiredFields::create('Email', 'Password')); // Focus on the email input when the page is loaded $js = <<<JS \t\t\t(function() { \t\t\t\tvar el = document.getElementById("MemberLoginForm_LoginForm_Email"); \t\t\t\tif(el && el.focus && (typeof jQuery == 'undefined' || jQuery(el).is(':visible'))) el.focus(); \t\t\t})(); JS; Requirements::customScript($js, 'MemberLoginFormFieldFocus'); }