function saveNewsArticle($data, Form $form) { try { $form->clearMessage(); $form->resetValidation(); if ($data['newsID']) { $this->manager->updateNews($data); } else { $this->manager->postNews($data); } Session::clear("FormInfo.Form_NewsRequestForm.data"); return Controller::curr()->redirect('/news-add/?saved=1'); } catch (EntityValidationException $ex1) { $messages = $ex1->getMessages(); $msg = $messages[0]; $form->addErrorMessage('Headline', $msg['message'], 'bad'); SS_Log::log($msg['message'], SS_Log::ERR); // Load errors into session and post back Session::set("FormInfo.Form_NewsRequestForm.data", $data); return $this->redirectBack(); } catch (Exception $ex) { $form->addErrorMessage('Headline', 'Server Error', 'bad'); SS_Log::log($ex->getMessage(), SS_Log::ERR); // Load errors into session and post back Session::set("FormInfo.Form_NewsRequestForm.data", $data); return $this->redirectBack(); } }
function SaveDeployment($data, $form) { $id = convert::raw2sql($data['DeploymentID']); // Only loaded if it belongs to current user $Deployment = $form->controller->LoadDeployment($id); // If a deployment wasn't returned, we'll create a new one if (!$Deployment) { $Deployment = new Deployment(); $Deployment->OrgID = Member::currentUser()->getCurrentOrganization()->ID; $newDeploy = true; } $form->saveInto($Deployment); $survey = $form->controller->GetCurrentSurvey(); $Deployment->DeploymentSurveyID = $survey->ID; $Deployment->UpdateDate = SS_Datetime::now()->Rfc2822(); $Deployment->OrgID = $survey->OrgID; $Deployment->write(); /**/ $survey->CurrentStep = 'MoreDeploymentDetails'; $survey->HighestStepAllowed = 'MoreDeploymentDetails'; $survey->UpdateDate = SS_Datetime::now()->Rfc2822(); $survey->write(); // If it is a new deployment and it is public, we send an email... if (isset($newDeploy) && $Deployment->IsPublic === 1) { global $email_new_deployment; global $email_from; $email = EmailFactory::getInstance()->buildEmail($email_from, $email_new_deployment, 'New Deployment'); $email->setTemplate('NewDeploymentEmail'); $email->populateTemplate(array('Deployment' => $Deployment)); $email->send(); } Session::set('CurrentDeploymentID', $Deployment->ID); Controller::curr()->redirect($form->controller->Link() . 'MoreDeploymentDetails'); }
/** * @param array $data * @return SS_HTTPResponse|void */ function doChangePassword(array $data) { try { $token = Session::get('AutoLoginHash'); $member = $this->password_manager->changePassword($token, @$data['NewPassword1'], @$data['NewPassword2']); Session::clear('AutoLoginHash'); $back_url = isset($_REQUEST['BackURL']) ? $_REQUEST['BackURL'] : '/'; return OpenStackIdCommon::loginMember($member, $back_url); } catch (InvalidResetPasswordTokenException $ex1) { Session::clear('AutoLoginHash'); Controller::curr()->redirect('login'); } catch (EmptyPasswordException $ex2) { $this->clearMessage(); $this->sessionMessage(_t('Member.EMPTYNEWPASSWORD', "The new password can't be empty, please try again"), "bad"); Controller::curr()->redirectBack(); } catch (PasswordMismatchException $ex3) { $this->clearMessage(); $this->sessionMessage(_t('Member.ERRORNEWPASSWORD', "You have entered your new password differently, try again"), "bad"); Controller::curr()->redirectBack(); } catch (InvalidPasswordException $ex4) { $this->clearMessage(); $this->sessionMessage(sprintf(_t('Member.INVALIDNEWPASSWORD', "We couldn't accept that password: %s"), nl2br("\n" . $ex4->getMessage())), "bad"); Controller::curr()->redirectBack(); } }
/** * This method returns the default configuration array structure of the * default map. It is used to initialize the OpenLayer JavaScript classes * after the page has been loaded. * * @return array Configuration array which is processed by JS:initMap */ public function getDefaultMapConfiguration() { $result = array(); $mapObject = $this->GetComponent('Map'); if ($mapObject && $mapObject->ID != 0) { $result = $mapObject->getConfigurationArray(); $cont = Controller::curr(); $request = $cont->getRequest(); if ($request) { if ($request->getVar('bbox')) { $param = $request->getVar('bbox'); $array = preg_split("/[\\s]*[,][\\s]*/", $param); if (sizeof($array) == 4) { $result['Latitude'] = ''; $result['Longitude'] = ''; $result['Zoom'] = ''; $extent['left'] = $array[0]; $extent['top'] = $array[1]; $extent['right'] = $array[2]; $extent['bottom'] = $array[3]; $result['Map']['DefaultExtent'] = $extent; } } } } return $result; }
/** * A form action that handles populating the record with mock data * * @param array $data The data that as passed in from the form * @param Form $form The Form object that was used * @return SSViewer */ public function doAddMockData($data, $form) { $this->owner->record->fill(array('only_empty' => true, 'include_relations' => false, 'download_images' => false)); Controller::curr()->getResponse()->addHeader("X-Pjax", "Content"); $link = Controller::join_links($this->owner->gridField->Link(), "item", $this->owner->record->ID); return Controller::curr()->redirect($link); }
public function allMethodNames($custom = false) { // A friendly hack to make hasMethod returns true if (Controller::has_curr()) { return array(Controller::curr()->getRequest()->param('Action')); } }
/** * A basic browser detection. * * if a browser is not here - assume it's a crawler or a bot. In which case, it shouldn't create a shortlist. * * @see http://stackoverflow.com/a/1537636 * */ public static function isBrowser() { // Regular expression to match common browsers $browserlist = '/(opera|aol|msie|firefox|chrome|konqueror|safari|netscape|navigator|mosaic|lynx|amaya|omniweb|avant|camino|flock|seamonkey|mozilla|gecko)+/i'; $userAgent = strtolower(Controller::curr()->getRequest()->getHeader('User-Agent')); return preg_match($browserlist, $userAgent) === 1; }
protected function saveAllRecords(\GridField $grid, $arguments, $data) { if (isset($data[$grid->Name])) { $currValue = $grid->Value(); $grid->setValue($data[$grid->Name]); $model = singleton($grid->List->dataClass()); foreach ($grid->getConfig()->getComponents() as $component) { if ($component instanceof \GridField_SaveHandler) { $component->handleSave($grid, $model); } } if ($this->publish) { // Only use the viewable list items, since bulk publishing can take a toll on the system $list = ($paginator = $grid->getConfig()->getComponentByType('GridFieldPaginator')) ? $paginator->getManipulatedData($grid, $grid->List) : $grid->List; $list->each(function ($item) { if ($item->hasExtension('Versioned')) { $item->writeToStage('Stage'); $item->publish('Stage', 'Live'); } }); } if ($model->exists()) { $model->delete(); $model->destroy(); } $grid->setValue($currValue); if (\Controller::curr() && ($response = \Controller::curr()->Response)) { if (!$this->completeMessage) { $this->completeMessage = _t('GridField.DONE', 'Done.'); } $response->addHeader('X-Status', rawurlencode($this->completeMessage)); } } }
/** * @param IRSVPTemplate $template * @param IRSVP $rsvp * @param ISummitEvent $event * @param string $form_name * @return BootstrapForm|PresentationSpeaker */ public function build(IRSVPTemplate $template, IRSVP $rsvp, ISummitEvent $event, $form_name = 'RSVPForm') { $fields = new FieldList(); foreach ($template->getQuestions() as $q) { $type = $q->Type(); $builder_class = $type . 'UIBuilder'; // @IRSVPQuestionTemplateUIBuilder $builder = Injector::inst()->create($builder_class); $answer = $rsvp ? $rsvp->findAnswerByQuestion($q) : null; $field = $builder->build($rsvp, $q, $answer); $fields->add($field); } $validator = null; if ($rsvp) { $fields->add(new HiddenField('rsvp_id', 'rsvp_id', $rsvp->getIdentifier())); } $fields->add(new HiddenField('event_id', 'event_id', $event->getIdentifier())); $fields->add(new HiddenField('summit_id', 'summit_id', $event->Summit()->getIdentifier())); $fields->add(new HiddenField('seat_type', 'seat_type', $event->getCurrentRSVPSubmissionSeatType())); $fields->add(new LiteralField('hr', '<hr>')); $actions = new FieldList(FormAction::create('submit_rsvp')->setTitle('Send RSVP')->addExtraClass('rsvp_submit')); $form = new BootstrapForm(Controller::curr(), $form_name . '_' . $event->getIdentifier(), $fields, $actions, $validator); $form->setAttribute('class', 'rsvp_form'); return $form; }
function StartSurvey($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_DeploymentSurveyRegistrationForm.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(); //Find or create the 'user' group if (!($userGroup = Group::get()->filter('Code', 'users')->first())) { $userGroup = new Group(); $userGroup->Code = "users"; $userGroup->Title = "Users"; $userGroup->Write(); $Member->Groups()->add($userGroup); } //Add member to user group $Member->Groups()->add($userGroup); $BackURL = Controller::curr()->Link('AboutYou'); return OpenStackIdCommon::loginMember($Member, $BackURL); }
function save($data, $form) { $response = new OSLogoProgramResponse(); $form->saveInto($response); // Combine these two fields so we just store a manually typed name in // $data[OtherCompany] if ($data['NonSponsorCompany']) { $response->OtherCompany = $data['NonSponsorCompany']; } $response->write(); // Now set the official company name for the email $data['CompanyName'] = 'Not Provided'; if ($response->OtherCompany) { $response->CompanyName = $response->OtherCompany; } elseif ($response->CompanyID != 0) { $company = Company::get()->byID($response->CompanyID); if ($company) { $response->CompanyName = $company->Name; } } // Email the logo email list $Subject = "Contact Form for Commercial Logo Inquiries"; $email = EmailFactory::getInstance()->buildEmail($data['Email'], OS_LOGO_PROGRAM_FORM_TO_EMAIL, $Subject); $email->setTemplate('OSLogoProgramResponseEmail'); $email->populateTemplate($response); $email->send(); if ($response->Program === 'Powered') { Controller::curr()->setMessage('success', 'Thanks for your interest in licensing the OpenStack Powered logo. Please review the interoperability standards at <a href="http://www.openstack.org/interop" class="alert-link">openstack.org/interop</a> page and submit test results according to the instructions.'); } return Controller::curr()->redirect(Controller::curr()->Link("thanks")); }
/** * Update any requests to limit the results to the current site */ public function augmentSQL(SQLQuery &$query, DataQuery &$dataQuery = null) { $ctrl = null; if (Controller::has_curr()) { $ctrl = Controller::curr(); } if (Subsite::$disable_subsite_filter) { return; } if ($dataQuery->getQueryParam('Subsite.filter') === false) { return; } if ($ctrl && get_class(Controller::curr()) == 'Security') { return; } // Don't run on delete queries, since they are always tied to // a specific ID. if ($query->getDelete()) { return; } // If you're querying by ID, ignore the sub-site - this is a bit ugly... // if(!$query->where || (strpos($query->where[0], ".\"ID\" = ") === false && strpos($query->where[0], ".`ID` = ") === false && strpos($query->where[0], ".ID = ") === false && strpos($query->where[0], "ID = ") !== 0)) { if (!$query->filtersOnID()) { if (Subsite::$force_subsite) { $subsiteID = Subsite::$force_subsite; } else { $subsiteID = (int) Subsite::currentSubsiteID(); } $froms = $query->getFrom(); $froms = array_keys($froms); $tableName = array_shift($froms); $query->addWhere("\"{$tableName}\".\"SubsiteID\" IN ({$subsiteID})"); } }
function Link() { $brandspage = Controller::curr()->data(); if ($brandspage->ProductGroupID && ($group = $brandspage->ProductGroup())) { return $group->Link() . "?Brand=" . $this->ID; } }
function saveLink($data, $form) { $url = $data['HostedMediaURL']; $EventID = Session::get('UploadMedia.PresentationID'); if ($EventID) { $Event = VideoPresentation::get()->byID($EventID); } // Attach a protocol if needed if (substr($url, 0, 7) != 'http://' && substr($url, 0, 8) != 'https://') { $url = 'http://' . $url; } if (!filter_var($url, FILTER_VALIDATE_URL)) { $form->sessionMessage('That does not appear to be a valid URL', 'bad'); return $this->controller()->redirectBack(); } elseif (!$Event) { $data["HasError"] = TRUE; return $this->controller()->Customise($data); } else { $Event->HostedMediaURL = $url; $Event->MediaType = 'URL'; $Event->write(); Session::set('UploadMedia.Success', TRUE); Session::set('UploadMedia.URL', $url); Session::set('UploadMedia.Type', 'URL'); Controller::curr()->redirect($form->controller()->link() . 'Success'); } }
public function getHTMLFragments($gridField) { $model = Injector::inst()->create($gridField->getModelClass()); $parent = SiteTree::get()->byId(Controller::curr()->currentPageID()); if (!$model->canCreate()) { return array(); } $children = $this->getAllowedChildren($parent); if (count($children) > 1) { $pageTypes = DropdownField::create("PageType", "Page Type", $children, $model->defaultChild()); $pageTypes->setFieldHolderTemplate("GridFieldSiteTreeAddNewButton_holder")->addExtraClass("gridfield-dropdown no-change-track"); if (!$this->buttonName) { $this->buttonName = _t('GridFieldSiteTreeAddNewButton.AddMultipleOptions', 'Add new', "Add button text for multiple options."); } } else { $keys = array_keys($children); $pageTypes = HiddenField::create('PageType', 'Page Type', $keys[0]); if (!$this->buttonName) { $this->buttonName = _t('GridFieldSiteTreeAddNewButton.Add', 'Add new {name}', 'Add button text for a single option.', array($children[$keys[0]])); } } $state = $gridField->State->GridFieldSiteTreeAddNewButton; $state->currentPageID = $parent->ID; $state->pageType = $parent->defaultChild(); $addAction = new GridField_FormAction($gridField, 'add', $this->buttonName, 'add', 'add'); $addAction->setAttribute('data-icon', 'add')->addExtraClass("no-ajax ss-ui-action-constructive dropdown-action"); $forTemplate = new ArrayData(array()); $forTemplate->Fields = new ArrayList(); $forTemplate->Fields->push($pageTypes); $forTemplate->Fields->push($addAction); Requirements::css(LUMBERJACK_DIR . "/css/lumberjack.css"); Requirements::javascript(LUMBERJACK_DIR . "/javascript/GridField.js"); return array($this->targetFragment => $forTemplate->renderWith("GridFieldSiteTreeAddNewButton")); }
function processPayment($data, $form) { //sanity checks for credentials if (!$this->Config()->get("API_UserName") || !$this->Config()->get("API_Password") || !$this->Config()->get("API_Signature")) { user_error('You are attempting to make a payment without the necessary credentials set', E_USER_ERROR); } $data = $this->Order()->BillingAddress()->toMap(); $paymenturl = $this->getTokenURL($this->Amount->Amount, $this->Amount->Currency, $data); $this->Status = "Pending"; $this->write(); if ($paymenturl) { Controller::curr()->redirect($paymenturl); //redirect to payment gateway /* $page = new Page(); $page->Title = 'Redirection to PayPal...'; $page->Logo = '<img src="' . $this->Config()->get("logo") . '" alt="Payments powered by PayPal"/>'; $page->Form = $this->PayPalForm(); $controller = new Page_Controller($page); $form = $controller->renderWith('PaymentProcessingPage'); return new Payment_Processing($form); */ return new Payment_Processing(); } $this->Message = _t('PayPalExpressCheckoutPayment.COULDNOTBECONTACTED', "PayPal could not be contacted"); $this->Status = 'Failure'; $this->write(); return new Payment_Failure($this->Message); }
/** * Handles the add action for the given DataObject. * * @param $gridField GridField * @param $actionName string * @param $arguments mixed * @param $data array * * @return null|SS_HTTPResponse * * @throws UnexpectedValueException */ public function handleAction(GridField $gridField, $actionName, $arguments, $data) { if ($actionName == 'add') { $dbField = $this->getDataObjectField(); $objClass = $gridField->getModelClass(); /** * @var DataObject $obj */ $obj = new $objClass(); if ($obj->hasField($dbField)) { $obj->setCastedField($dbField, $data['gridfieldaddbydbfield'][$obj->ClassName][$dbField]); if ($obj->canCreate()) { $id = $gridField->getList()->add($obj); if (!$id) { $gridField->setError(_t('GridFieldAddByDBField.AddFail', 'Unable to save {class} to the database.', 'Unable to add the DataObject.', array('class' => get_class($obj))), 'error'); } } else { return Security::permissionFailure(Controller::curr(), _t('GridFieldAddByDBField.PermissionFail', 'You don\'t have permission to create a {class}.', 'Unable to add the DataObject.', array('class' => get_class($obj)))); } } else { throw new UnexpectedValueException(sprintf('Invalid field (%s) on %s.', $dbField, $obj->ClassName)); } } return null; }
/** * Method for allowing a user to reset their password * @param {stdClass} $data Data passed from ActionScript * @return {array} Returns a standard response array */ public function lostPassword($data) { $response = CodeBank_ClientAPI::responseBase(); $response['login'] = true; $SQL_email = Convert::raw2sql($data->user); $member = Member::get_one('Member', "\"Email\"='{$SQL_email}'"); // Allow vetoing forgot password requests $sng = new MemberLoginForm(Controller::has_curr() ? Controller::curr() : singleton('Controller'), 'LoginForm'); $results = $sng->extend('forgotPassword', $member); if ($results && is_array($results) && in_array(false, $results, true)) { $response['status'] = 'HELO'; $response['message'] = _t('CodeBankAPI.PASSWORD_SENT_TEXT', "A reset link has been sent to '{email}', provided an account exists for this email address.", array('email' => $data['Email'])); } if ($member) { $token = $member->generateAutologinTokenAndStoreHash(); $e = Member_ForgotPasswordEmail::create(); $e->populateTemplate($member); $e->populateTemplate(array('PasswordResetLink' => Security::getPasswordResetLink($member, $token))); $e->setTo($member->Email); $e->send(); $response['status'] = 'HELO'; $response['message'] = _t('CodeBankAPI.PASSWORD_SENT_TEXT', "A reset link has been sent to '{email}', provided an account exists for this email address.", array('email' => $data->user)); } else { if (!empty($data->user)) { $response['status'] = 'HELO'; $response['message'] = _t('CodeBankAPI.PASSWORD_SENT_TEXT', "A reset link has been sent to '{email}', provided an account exists for this email address.", array('email' => $data->user)); } else { $response['status'] = 'EROR'; $response['message'] = _t('Member.ENTEREMAIL', 'Please enter an email address to get a password reset link.'); } } return $response; }
/** * Update the corresponding vanity mapping. */ public function onBeforeWrite() { parent::onBeforeWrite(); // Retrieve the vanity mapping URL, where this is only possible using the POST variable. $vanityURL = is_null($URL = Controller::curr()->getRequest()->postVar('VanityURL')) ? $this->owner->VanityMapping()->MappedLink : $URL; $mappingExists = $this->owner->VanityMapping()->exists(); // Determine whether the vanity mapping URL has been updated. if ($vanityURL && $mappingExists) { if ($this->owner->VanityMapping()->MappedLink !== $vanityURL) { // Update the corresponding vanity mapping. $this->owner->VanityMapping()->MappedLink = $vanityURL; $this->owner->VanityMapping()->write(); } } else { if ($vanityURL) { // Instantiate the vanity mapping. $mapping = singleton('MisdirectionService')->createPageMapping($vanityURL, $this->owner->ID, 2); $this->owner->VanityMappingID = $mapping->ID; } else { if ($mappingExists) { // Remove the corresponding vanity mapping. $this->owner->VanityMapping()->delete(); } } } }
/** * Modified version of Breadcrumbs, to cater for viewing items. */ public function Breadcrumbs($maxDepth = 20, $unlinked = false, $stopAtPageType = false, $showHidden = false) { $page = $this; $pages = array(); while ($page && (!$maxDepth || count($pages) < $maxDepth) && (!$stopAtPageType || $page->ClassName != $stopAtPageType)) { if ($showHidden || $page->ShowInMenus || $page->ID == $this->ID) { $pages[] = $page; } $page = $page->Parent; } // Add on the item we're currently showing. $controller = Controller::curr(); if ($controller) { $request = $controller->getRequest(); if ($request->param('Action') == 'show') { $id = $request->param('ID'); if ($id) { $object = DataObject::get_by_id($this->getDataClass(), $id); array_unshift($pages, $object); } } } $template = new SSViewer('BreadcrumbsTemplate'); return $template->process($this->customise(new ArrayData(array('Pages' => new ArrayList(array_reverse($pages)))))); }
public function overridePartialTemplates($viewer, $templates = array(), $action = null) { // find the theme from the current page $current = Controller::curr(); $partial = null; if ($current->hasMethod('appliedPartialTheme')) { $partial = $current->appliedPartialTheme(); } // check for alternative 'sub' templates if (!$partial) { return $viewer; } $alts = $this->findAlternate($partial, $templates, $action); if ($alts) { if (isset($alts['Layout'])) { $viewer->setTemplateFile('Layout', $alts['Layout']); } if (isset($alts['main'])) { $viewer->setTemplateFile('main', $alts['main']); } if (isset($alts['Includes'])) { $viewer->setTemplateFile('main', $alts['Includes']); } } return $viewer; }
/** * Returns a DataList containing Pages. * The provided links point to their translated pages. * You can use it in templates like this: * * <% loop LanguageChooser %> * $Title, $Current, and any other vars in your page instance * <% end_loop %> * * @return DataList */ public function LanguageChooser() { if (!Controller::curr()) { return; } if ($langs = Translatable::get_allowed_locales()) { $data = ArrayList::create(); foreach ($langs as $key => $code) { if ($code == Translatable::get_current_locale()) { $this->owner->Current = 'current'; $data->push($this->owner); } else { $translation = $this->owner->getTranslation($code); if ($translation) { $data->push($translation); } else { $page = Translatable::get_one_by_locale("SiteTree", $code, "URLSegment LIKE 'home%'"); if ($page) { $data->push($page); } } } } return $data; } return false; }
function submit($data, $form) { $member = Member::currentUser(); if (!$member || !$member->inGroup("ADMIN")) { $form->setMessage("You need to be logged as an admin to send this email.", "bad"); return Controller::curr()->redirectBack(); } $data = Convert::raw2sql($data); $page = null; if (isset($data["ModuleProductID"])) { $page = ModuleProduct::get()->byID(intval($data["ModuleProductID"])); } if (!$page) { $form->setMessage("Can not find the right page for saving this email.", "bad"); return Controller::curr()->redirectBack(); } $email = new ModuleProductEmail(); $form->saveInto($email); $email->write(); if (Director::is_ajax()) { return "mail sent!"; } else { return Controller::curr()->redirect($page->Link()); } }
/** * Update the searchable fields and model admin filtering, allowing CMS searchable content tagging. */ public function updateSearchableFields(&$fields) { // Instantiate a field containing the existing tags. $fields = array_merge(array('Tagging' => array('title' => 'Tags', 'field' => ListboxField::create('Tagging', 'Tags', FusionTag::get()->map('Title', 'Title')->toArray(), ($filtering = Controller::curr()->getRequest()->getVar('q')) && isset($filtering['Tagging']) ? $filtering['Tagging'] : array(), null, true), 'filter' => $this->owner->dbObject('Tagging')->stat('default_search_filter_class'))), $fields); // Allow extension. $this->owner->extend('updateTaggingExtensionSearchableFields', $fields); }
/** * @param ISurveyStep $step * @param string $action * @param string $form_name * @return Form */ public function build(ISurveyStep $step, $action, $form_name = 'SurveyStepForm') { $fields = new FieldList(); $form = new ThankYouStepForm(Controller::curr(), $form_name, $fields, $actions = new FieldList(), $step, $validator = array()); $form->setAttribute('class', 'survey_step_form'); return $form; }
/** * * @param type $dummy * @return void */ public function init(&$dummy) { $controller = Controller::curr(); if (get_class($controller) == 'AssetAdmin' || get_class($controller) == 'CMSFileAddController') { die('This module disabled usage of AssetAdmin or CMSFileAddController'); } }
private function Form() { $fields = FieldList::create(TextField::create('Title'), TextField::create('Subtitle')); $actions = FieldList::create(FormAction::create('submit', 'submit')); $validator = ZenValidator::create(); return Form::create(Controller::curr(), 'Form', $fields, $actions, $validator); }
function StartSurvey($data, $form) { try { $data = SQLDataCleaner::clean($data); $data['MembershipType'] = 'community'; Session::set("FormInfo.{$form->FormName()}.data", $data); $profile_page = EditProfilePage::get()->first(); $member = $this->member_manager->registerMobile($data, new MemberRegistrationSenderService()); //Get profile page if (!is_null($profile_page)) { //Redirect to profile page with success message Session::clear("FormInfo.{$form->FormName()}.data"); $request = Controller::curr()->getRequest(); $back_url = $request->postVar('BackURL'); $link = $profile_page->Link('?success=1'); if (!empty($back_url)) { $link .= "&BackURL=" . $back_url; } return OpenStackIdCommon::loginMember($member, $link); } } catch (EntityValidationException $ex1) { Form::messageForForm($form->FormName(), $ex1->getMessage(), 'bad'); //Return back to form SS_Log::log($ex1->getMessage(), SS_Log::WARN); return Controller::curr()->redirectBack(); } catch (Exception $ex) { Form::messageForForm($form->FormName(), "There was an error with your request, please contact your admin.", 'bad'); //Return back to form SS_Log::log($ex->getMessage(), SS_Log::ERR); return Controller::curr()->redirectBack(); } }
public function getCMSFields() { $fields = parent::getCMSFields(); $subsites = DataObject::get('Subsite'); if (!$subsites) { $subsites = new ArrayList(); } else { $subsites = ArrayList::create($subsites->toArray()); } $subsites->push(new ArrayData(array('Title' => 'Main site', 'ID' => 0))); $fields->addFieldToTab('Root.Main', DropdownField::create("CopyContentFromID_SubsiteID", _t('SubsitesVirtualPage.SubsiteField', "Subsite"), $subsites->map('ID', 'Title'))->addExtraClass('subsitestreedropdownfield-chooser no-change-track'), 'CopyContentFromID'); // Setup the linking to the original page. $pageSelectionField = new SubsitesTreeDropdownField("CopyContentFromID", _t('VirtualPage.CHOOSE', "Choose a page to link to"), "SiteTree", "ID", "MenuTitle"); if (Controller::has_curr() && Controller::curr()->getRequest()) { $subsiteID = Controller::curr()->getRequest()->requestVar('CopyContentFromID_SubsiteID'); $pageSelectionField->setSubsiteID($subsiteID); } $fields->replaceField('CopyContentFromID', $pageSelectionField); // Create links back to the original object in the CMS if ($this->CopyContentFromID) { $editLink = "admin/pages/edit/show/{$this->CopyContentFromID}/?SubsiteID=" . $this->CopyContentFrom()->SubsiteID; $linkToContent = "\n\t\t\t\t<a class=\"cmsEditlink\" href=\"{$editLink}\">" . _t('VirtualPage.EDITCONTENT', 'Click here to edit the content') . "</a>"; $fields->removeByName("VirtualPageContentLinkLabel"); $fields->addFieldToTab("Root.Main", $linkToContentLabelField = new LabelField('VirtualPageContentLinkLabel', $linkToContent), 'Title'); $linkToContentLabelField->setAllowHTML(true); } $fields->addFieldToTab('Root.Main', TextField::create('CustomMetaTitle', $this->fieldLabel('CustomMetaTitle'))->setDescription(_t('SubsitesVirtualPage.OverrideNote', 'Overrides inherited value from the source')), 'MetaTitle'); $fields->addFieldToTab('Root.Main', TextareaField::create('CustomMetaKeywords', $this->fieldLabel('CustomMetaTitle'))->setDescription(_t('SubsitesVirtualPage.OverrideNote')), 'MetaKeywords'); $fields->addFieldToTab('Root.Main', TextareaField::create('CustomMetaDescription', $this->fieldLabel('CustomMetaTitle'))->setDescription(_t('SubsitesVirtualPage.OverrideNote')), 'MetaDescription'); $fields->addFieldToTab('Root.Main', TextField::create('CustomExtraMeta', $this->fieldLabel('CustomMetaTitle'))->setDescription(_t('SubsitesVirtualPage.OverrideNote')), 'ExtraMeta'); return $fields; }
function __destruct() { // Shift off anything else that's on the stack. This can happen if something throws // an exception that causes a premature TestSession::__destruct() call while(Controller::curr() != $this->controller) Controller::curr()->popCurrent(); $this->controller->popCurrent(); }