Example #1
0
 public function testLoadDataFromIgnoreFalseish()
 {
     $form = new Form(new Controller(), 'Form', new FieldList(new TextField('Biography', 'Biography', 'Custom Default')), new FieldList());
     $captainNoDetails = $this->objFromFixture('FormTest_Player', 'captainNoDetails');
     $captainWithDetails = $this->objFromFixture('FormTest_Player', 'captainWithDetails');
     $form->loadDataFrom($captainNoDetails, Form::MERGE_IGNORE_FALSEISH);
     $this->assertEquals($form->getData(), array('Biography' => 'Custom Default'), 'LoadDataFrom() doesn\'t overwrite fields when MERGE_IGNORE_FALSEISH set and values are false-ish');
     $form->loadDataFrom($captainWithDetails, Form::MERGE_IGNORE_FALSEISH);
     $this->assertEquals($form->getData(), array('Biography' => 'Bio 1'), 'LoadDataFrom() does overwrite fields when MERGE_IGNORE_FALSEISH set and values arent false-ish');
 }
Example #2
0
 public function testLoadDataFromClearMissingFields()
 {
     $form = new Form(new Controller(), 'Form', new FieldSet(new HeaderField('MyPlayerHeader', 'My Player'), new TextField('Name'), new TextareaField('Biography'), new DateField('Birthday'), new NumericField('BirthdayYear'), $unrelatedField = new TextField('UnrelatedFormField')), new FieldSet());
     $unrelatedField->setValue("random value");
     $captainWithDetails = $this->objFromFixture('FormTest_Player', 'captainWithDetails');
     $captainNoDetails = $this->objFromFixture('FormTest_Player', 'captainNoDetails');
     $form->loadDataFrom($captainWithDetails);
     $this->assertEquals($form->getData(), array('Name' => 'Captain Details', 'Biography' => 'Bio 1', 'Birthday' => '1982-01-01', 'BirthdayYear' => '1982', 'UnrelatedFormField' => 'random value'), 'LoadDataFrom() doesnt overwrite fields not found in the object');
     $captainWithDetails = $this->objFromFixture('FormTest_Player', 'captainNoDetails');
     $team2 = $this->objFromFixture('FormTest_Team', 'team2');
     $form->loadDataFrom($captainWithDetails);
     $form->loadDataFrom($team2, true);
     $this->assertEquals($form->getData(), array('Name' => 'Team 2', 'Biography' => '', 'Birthday' => '', 'BirthdayYear' => 0, 'UnrelatedFormField' => null), 'LoadDataFrom() overwrites fields not found in the object with $clearMissingFields=true');
 }
 public function testGetFormFields()
 {
     $fields = singleton('FormScaffolderTest_Article')->getFrontEndFields();
     $form = new Form(new Controller(), 'TestForm', $fields, new FieldList());
     $form->loadDataFrom(singleton('FormScaffolderTest_Article'));
     $this->assertFalse($fields->hasTabSet(), 'getFrontEndFields() doesnt produce a TabSet by default');
 }
 /**
  * @return Form
  */
 function getEditForm($id = null, $fields = null)
 {
     $siteConfig = SiteConfig::current_site_config();
     $fields = $siteConfig->getCMSFields();
     $actions = $siteConfig->getCMSActions();
     $form = new Form($this, 'EditForm', $fields, $actions);
     $form->addExtraClass('root-form');
     $form->addExtraClass('cms-edit-form cms-panel-padded center');
     // don't add data-pjax-fragment=CurrentForm, its added in the content template instead
     if ($form->Fields()->hasTabset()) {
         $form->Fields()->findOrMakeTab('Root')->setTemplate('CMSTabSet');
     }
     $form->setHTMLID('Form_EditForm');
     $form->loadDataFrom($siteConfig);
     $form->setTemplate($this->getTemplatesWithSuffix('_EditForm'));
     // Use <button> to allow full jQuery UI styling
     $actions = $actions->dataFields();
     if ($actions) {
         foreach ($actions as $action) {
             $action->setUseButtonTag(true);
         }
     }
     $this->extend('updateEditForm', $form);
     return $form;
 }
 public function ExpandableForm()
 {
     if ($this->formorfields instanceof FieldList) {
         $fields = $this->formorfields;
     } else {
         if ($this->formorfields instanceof ViewableData) {
             $form = $this->formorfields;
         } else {
             if ($this->record->hasMethod('getExandableForm')) {
                 $form = $this->record->getExandableForm($this, __FUNCTION__);
                 $this->record->extend('updateExandableForm', $form);
             } else {
                 if ($this->record->hasMethod('getExandableFormFields')) {
                     $fields = $this->record->getExandableFormFields();
                     $this->record->extend('updateExandableFormFields', $fields);
                 } else {
                     $fields = $this->record->scaffoldFormFields();
                     $this->record->extend('updateExandableFormFields', $fields);
                 }
             }
         }
     }
     if (empty($form)) {
         $actions = new FieldList();
         $actions->push(FormAction::create('doSave', _t('GridFieldDetailForm.Save', 'Save'))->setUseButtonTag(true)->addExtraClass('ss-ui-action-constructive')->setAttribute('data-icon', 'accept')->setAttribute('data-action-type', 'default'));
         $form = new Form($this, 'ExpandableForm', $fields, $actions, $this->validator);
     }
     $form->loadDataFrom($this->record, Form::MERGE_DEFAULT);
     $form->IncludeFormTag = false;
     return $form;
 }
 /**
  * Returns the edit form for this admin.
  * 
  * @param type $id
  * @param type $fields
  * 
  * @return Form
  */
 public function getEditForm($id = null, $fields = null)
 {
     $fields = new FieldList();
     $desc = _t('SilvercartProductImageAdmin.Description');
     $descriptionField = new SilvercartAlertInfoField('SilvercartProductImagesDescription', str_replace(PHP_EOL, '<br/>', $desc));
     $uploadField = new UploadField('SilvercartProductImages', _t('SilvercartProductImageAdmin.UploadProductImages', 'Upload product images'));
     $uploadField->setFolderName(SilvercartProductImageImporter::get_relative_upload_folder());
     $fields->push($uploadField);
     $fields->push($descriptionField);
     if (!SilvercartProductImageImporter::is_installed()) {
         $cronTitle = _t('SilvercartProductImageAdmin.CronNotInstalledTitle') . ':';
         $cron = _t('SilvercartProductImageAdmin.CronNotInstalledDescription');
         $cronjobInfoField = new SilvercartAlertDangerField('SilvercartProductImagesCronjobInfo', str_replace(PHP_EOL, '<br/>', $cron), $cronTitle);
         $fields->insertAfter('SilvercartProductImages', $cronjobInfoField);
     } elseif (SilvercartProductImageImporter::is_running()) {
         $cronTitle = _t('SilvercartProductImageAdmin.CronIsRunningTitle') . ':';
         $cron = _t('SilvercartProductImageAdmin.CronIsRunningDescription');
         $cronjobInfoField = new SilvercartAlertSuccessField('SilvercartProductImagesCronjobInfo', str_replace(PHP_EOL, '<br/>', $cron), $cronTitle);
         $fields->insertAfter('SilvercartProductImages', $cronjobInfoField);
     }
     $uploadedFiles = $this->getUploadedFiles();
     if (count($uploadedFiles) > 0) {
         $uploadedFilesInfo = '<br/>' . implode('<br/>', $uploadedFiles);
         $fileInfoField = new SilvercartAlertWarningField('SilvercartProductImagesFileInfo', $uploadedFilesInfo, _t('SilvercartProductImageAdmin.FileInfoTitle'));
         $fields->insertAfter('SilvercartProductImages', $fileInfoField);
     }
     $actions = new FieldList();
     $form = new Form($this, "EditForm", $fields, $actions);
     $form->addExtraClass('cms-edit-form cms-panel-padded center ' . $this->BaseCSSClasses());
     $form->loadDataFrom($this->request->getVars());
     $this->extend('updateEditForm', $form);
     return $form;
 }
 /**
  * @return Form|SS_HTTPResponse
  */
 public function EditProfileForm()
 {
     if (!Member::currentUser()) {
         $this->setFlash(_t('EditProfilePage.LoginWarning', 'Please login to edit your profile'), 'warning');
         return $this->redirect(Director::absoluteBaseURL());
     }
     $firstName = new TextField('FirstName');
     $firstName->setAttribute('placeholder', _t('EditProfilePage.FirstNamePlaceholder', 'Enter your first name'))->setAttribute('required', 'required')->addExtraClass('form-control');
     $surname = new TextField('Surname');
     $surname->setAttribute('placeholder', _t('EditProfilePage.SurnamePlaceholder', 'Enter your surname'))->setAttribute('required', 'required')->addExtraClass('form-control');
     $email = new EmailField('Email');
     $email->setAttribute('placeholder', _t('EditProfilePage.EmailPlaceholder', 'Enter your email address'))->setAttribute('required', 'required')->addExtraClass('form-control');
     $jobTitle = new TextField('JobTitle');
     $jobTitle->setAttribute('placeholder', _t('EditProfilePage.JobTitlePlaceholder', 'Enter your job title'))->addExtraClass('form-control');
     $website = new TextField('Website');
     $website->setAttribute('placeholder', _t('EditProfilePage.WebsitePlaceholder', 'Enter your website'))->addExtraClass('form-control');
     $blurb = new TextareaField('Blurb');
     $blurb->setAttribute('placeholder', _t('EditProfilePage.BlurbPlaceholder', 'Enter your blurb'))->addExtraClass('form-control');
     $confirmPassword = new ConfirmedPasswordField('Password', _t('EditProfilePage.PasswordLabel', 'New Password'));
     $confirmPassword->canBeEmpty = true;
     $confirmPassword->setAttribute('placeholder', _t('EditProfilePage.PasswordPlaceholder', 'Enter your password'))->addExtraClass('form-control');
     $fields = new FieldList($firstName, $surname, $email, $jobTitle, $website, $blurb, $confirmPassword);
     $action = new FormAction('SaveProfile', _t('EditProfilePage.SaveProfileText', 'Update Profile'));
     $action->addExtraClass('btn btn-primary btn-lg');
     $actions = new FieldList($action);
     // Create action
     $validator = new RequiredFields('FirstName', 'Email');
     //Create form
     $form = new Form($this, 'EditProfileForm', $fields, $actions, $validator);
     //Populate the form with the current members data
     $Member = Member::currentUser();
     $form->loadDataFrom($Member->data());
     //Return the form
     return $form;
 }
 /**
  * @return Form
  * @todo what template is used here? AssetAdmin_UploadContent.ss doesn't seem to be used anymore
  */
 public function getEditForm($id = null, $fields = null)
 {
     Requirements::javascript(FRAMEWORK_DIR . '/javascript/AssetUploadField.js');
     Requirements::css(FRAMEWORK_DIR . '/css/AssetUploadField.css');
     $folder = $this->currentPage();
     $uploadField = UploadField::create('AssetUploadField', '');
     $uploadField->setConfig('previewMaxWidth', 40);
     $uploadField->setConfig('previewMaxHeight', 30);
     $uploadField->addExtraClass('ss-assetuploadfield');
     $uploadField->removeExtraClass('ss-uploadfield');
     $uploadField->setTemplate('AssetUploadField');
     if ($folder->exists() && $folder->getFilename()) {
         // The Upload class expects a folder relative *within* assets/
         $path = preg_replace('/^' . ASSETS_DIR . '\\//', '', $folder->getFilename());
         $uploadField->setFolderName($path);
     } else {
         $uploadField->setFolderName(ASSETS_DIR);
     }
     $exts = $uploadField->getValidator()->getAllowedExtensions();
     asort($exts);
     $form = new Form($this, 'getEditForm', new FieldList($uploadField, new LiteralField('AllowedExtensions', sprintf('<p>%s: %s</p>', _t('AssetAdmin.ALLOWEDEXTS', 'Allowed extensions'), implode('<em>, </em>', $exts))), new HiddenField('ID')), new FieldList());
     $form->addExtraClass('center cms-edit-form ' . $this->BaseCSSClasses());
     // Don't use AssetAdmin_EditForm, as it assumes a different panel structure
     $form->setTemplate($this->getTemplatesWithSuffix('_EditForm'));
     $form->Fields()->push(new LiteralField('BackLink', sprintf('<a href="%s" class="backlink ss-ui-button cms-panel-link" data-icon="back">%s</a>', Controller::join_links(singleton('AssetAdmin')->Link('show'), $folder ? $folder->ID : 0), _t('AssetAdmin.BackToFolder', 'Back to folder'))));
     $form->loadDataFrom($folder);
     return $form;
 }
 /**
  * returns the form
  * @return Form
  */
 public function getGoogleSiteSearchForm($name = "GoogleSiteSearchForm")
 {
     $formIDinHTML = "Form_" . $name;
     if ($page = GoogleCustomSearchPage::get()->first()) {
         Requirements::javascript(THIRDPARTY_DIR . '/jquery/jquery.js');
         Requirements::javascript('googlecustomsearch/javascript/GoogleCustomSearch.js');
         $apiKey = Config::inst()->get("GoogleCustomSearchExt", "api_key");
         $cxKey = Config::inst()->get("GoogleCustomSearchExt", "cx_key");
         if ($apiKey && $cxKey) {
             Requirements::customScript("\n\t\t\t\t\t\tGoogleCustomSearch.apiKey = '" . $apiKey . "';\n\t\t\t\t\t\tGoogleCustomSearch.cxKey = '" . $cxKey . "';\n\t\t\t\t\t\tGoogleCustomSearch.formSelector = '#" . $formIDinHTML . "';\n\t\t\t\t\t\tGoogleCustomSearch.inputFieldSelector = '#" . $formIDinHTML . "_search';\n\t\t\t\t\t\tGoogleCustomSearch.resultsSelector = '#" . $formIDinHTML . "_Results';\n\t\t\t\t\t", "GoogleCustomSearchExt");
             $form = new Form($this->owner, 'GoogleSiteSearchForm', new FieldList($searchField = new TextField('search'), $resultField = new LiteralField($name . "_Results", "<div id=\"" . $formIDinHTML . "_Results\"></div>")), new FieldList(new FormAction('doSearch', _t("GoogleCustomSearchExt.GO", "Full Results"))));
             $form->setFormMethod('GET');
             if ($page = GoogleCustomSearchPage::get()->first()) {
                 $form->setFormAction($page->Link());
             }
             $form->disableSecurityToken();
             $form->loadDataFrom($_GET);
             $searchField->setAttribute("autocomplete", "off");
             $form->setAttribute("autocomplete", "off");
             return $form;
         } else {
             user_error("You must set an API Key and a CX key in your configs to use the Google Custom Search Form", E_USER_NOTICE);
         }
     } else {
         user_error("You must create a GoogleCustomSearchPage first.", E_USER_NOTICE);
     }
 }
Example #10
0
 function TrialSignupForm()
 {
     $cardType = array("visa" => "<img src='themes/attwiz/images/visa.png' height=30px></img>", "mc" => "<img src='themes/attwiz/images/mastercard.jpeg' height=30px></img>", "amex" => "<img src='themes/attwiz/images/ae.jpeg' height=30px></img>", "discover" => "<img src='themes/attwiz/images/discover.jpeg' height=30px></img>");
     $monthArray = array();
     for ($i = 1; $i <= 12; $i++) {
         $monthArray[$i] = date('F', mktime(0, 0, 0, $i));
     }
     $yearArray = array();
     $currentYear = date('Y');
     for ($i = 0; $i <= 10; $i++) {
         $yearArray[$currentYear + $i] = $currentYear + $i;
     }
     $trialExpiryDate = date('F-j-Y', mktime(0, 0, 0, date('n') + 1, date('j'), date('Y')));
     $subscriptionInfo = "<div id='SubscriptionInfo'><h2>Post-Trial Subscription Selection</h2>\n\t    <p>Your 10 heatmaps will expire on {$trialExpiryDate}, at which time your account \n\t    will be replenished with a new allocation of heatmap credits according to the \n\t    subscription level you choose below. You may cancel your subscription any time \n\t    before your trial period ends and your  credit card will only be charged 1 dollar.</p></div>";
     $subscriptionType = array("1" => "Bronze - (10 heatmaps for \$27.00 / month)", "2" => "Silver - (50 heatmaps for \$97.00 / month)", "3" => "Gold - (200 heatmaps for \$197.00 / month)");
     $whatsThis = '<span id="WhatsThis"><a id="WhatsThisImage" href="themes/attwiz/images/cvv.jpg" title="What\'s this?">What\'s this?</a></span>';
     $fields = new FieldList(new TextField('FirstName', 'First Name'), new TextField('LastName', 'Last Name'), new TextField('Company', 'Company(optional)'), new TextField('StreetAddress1', 'Street Address1'), new TextField('StreetAddress2', 'Street Address2(optional)'), new TextField('City', 'City'), new TextField('State', 'State/Province'), new TextField('PostalCode', 'Zip/Poatal Code'), new CountryDropdownField('Country'), new OptionsetField('CreditCardType', 'Credit Card Type', $cardType, 'visa'), new TextField('NameOnCard', 'Name On Card'), new NumericField('CreditCardNumber', 'Credit Card Number'), new PasswordField('CVVCode', 'Security/CVV Code'), new LiteralField('WhatIsThis', $whatsThis), new DropdownField('ExpirationMonth', 'Expiration Date', $monthArray), new DropdownField('ExpirationYear', '', $yearArray), new LiteralField('SubscriptionInfo', $subscriptionInfo), new OptionsetField('SubscriptionType', '', $subscriptionType, '1'), new CheckboxField('Agreement', ' I understand that this is a recurring subscription and I will be billed monthly unless I cancel.'));
     // Create action
     $actions = new FieldList($submit = new FormAction('doSignup', 'Start Trial'));
     $submit->setAttribute('src', 'themes/attwiz/images/button_startmytrialnow.gif');
     // Create action
     $validator = new RequiredFields('FirstName', 'LastName', 'StreetAddress1', 'City', 'State', 'PoatalCode', 'Country', 'CreditCardType', 'NameOnCard', 'CreditCardNumber', 'CVVCode', 'ExpirationMonth', 'ExpirationYear', 'SubscriptionInfo', 'SubscriptionType');
     $validator = null;
     $form = new Form($this, 'TrialSignupForm', $fields, $actions, $validator);
     $data = Session::get("FormInfo.Form_TrialSignupForm.data");
     if (is_array($data)) {
         $form->loadDataFrom($data);
     }
     return $form;
 }
 public function RegistrationForm()
 {
     if ($this->request->getVar('key') && $this->request->getVar('token')) {
         $key = $this->request->getVar('key');
         $token = $this->request->getVar('token');
     } else {
         if ($this->request->isPOST()) {
             $key = $this->request->requestVar('Key');
             $token = $this->request->requestVar('Token');
         }
     }
     if ($key && $token) {
         $memory = ContributorMaps_Data::get()->filter(array('Unique_Key' => $key, 'EditToken' => $token, 'EditTokenExpires:GreaterThanOrEqual' => date('Y-m-d')))->First();
         if (!$memory) {
             return $this->redirect($this->Link("?action=edit&status=2"));
         }
     } else {
         if (Session::get("FormInfo.RegistrationForm_Edit.data")) {
             $memory = Session::get("FormInfo.RegistrationForm_Edit.data");
         }
     }
     $fields = new FieldList(new TextField('Name', 'Name*'), new TextField('Surname', 'Surname*'), new EmailField('Email', 'Email*'), new TextField('Location', 'Location* (e.g. Berlin, Deutschland)'), new HeaderField('Skills'), new CheckboxField('Skills_Design', 'Design'), new CheckboxField('Skills_Dev', 'Development'), new CheckboxField('Skills_Doc', 'Documentation'), new CheckboxField('Skills_Infra', 'Infrastructure'), new CheckboxField('Skills_l10n', 'Localisation'), new CheckboxField('Skills_Marketing', 'Marketing'), new CheckboxField('Skills_QA', 'Quality Assurance'), new CheckboxField('Skills_Base', 'Support - Base'), new CheckboxField('Skills_Calc', 'Support - Calc'), new CheckboxField('Skills_Draw', 'Support - Draw'), new CheckboxField('Skills_Impress', 'Support - Impress'), new CheckboxField('Skills_Math', 'Support - Math'), new CheckboxField('Skills_Writer', 'Support - Writer'));
     if ($memory) {
         $fields->push(new HiddenField('Key', '', $key));
         $fields->push(new HiddenField('Token', '', $token));
         $actions = new FieldList(new FormAction('processEditForm', 'Update'));
     } else {
         $recaptcha = new RecaptchaField('Captcha');
         $recaptcha->jsOptions = array('theme' => 'white');
         $fields->push($recaptcha);
         $actions = new FieldList(new FormAction('processForm', 'Register'));
     }
     $validator = new RequiredFields('Name', 'Surname', 'Email', 'Location');
     $form = new Form($this, 'RegistrationForm', $fields, $actions, $validator);
     //Load previously submitted data
     if ($memory) {
         $form->loadDataFrom($memory);
         Session::clear("FormInfo.{$form->FormName()}_Edit.data");
     } else {
         if (Session::get("FormInfo.{$form->FormName()}.data")) {
             $form->loadDataFrom(Session::get("FormInfo.{$form->FormName()}.data"));
             Session::clear("FormInfo.{$form->FormName()}.data");
         }
     }
     return $form;
 }
 /**
  * This form is exactly like the CMS form.  It gives us an opportunity to test the fields outside of the CMS context
  */
 function Form()
 {
     $fields = $this->getCMSFields();
     $actions = new FieldSet(new FormAction("save", "Save"), new ImageFormAction("gohome", "Go home", "frameworktest/images/test-button.png"));
     $form = new Form($this, "Form", $fields, $actions);
     $form->loadDataFrom($this->dataRecord);
     return $form;
 }
 public function testFormValidation()
 {
     $form = new Form(new Controller(), 'Form', new FieldList($field = new ConfirmedPasswordField('Password')), new FieldList());
     $form->loadDataFrom(array('Password' => array('_Password' => '123', '_ConfirmPassword' => '999')));
     $this->assertEquals('123', $field->children->first()->Value());
     $this->assertEquals('999', $field->children->last()->Value());
     $this->assertNotEquals($field->children->first()->Value(), $field->children->last()->Value());
 }
 /**
  * @return Form
  */
 public function AddForm()
 {
     $method = $this->parent->parent->getOption('ExtraFields');
     $fields = $this->item->{$method}($this->parent->parent->parent);
     $form = new Form($this, 'AddForm', $fields, new FieldSet(new FormAction('doAdd', _t('ItemSetField.ADD', 'Add'))));
     $form->loadDataFrom($this->item);
     return $form;
 }
Example #15
0
 function HasManyForm()
 {
     $team = DataObject::get_one('ComplexTableFieldTest_Team', "\"Name\" = 'The Awesome People'");
     $sponsorsField = new ComplexTableField($this, 'Sponsors', $team->Sponsors(), ComplexTableFieldTest_Sponsor::$summary_fields, 'getCMSFields');
     $form = new Form($this, 'HasManyForm', new FieldList(new HiddenField('ID', '', $team->ID), $sponsorsField), new FieldList(new FormAction('doSubmit', 'Submit')));
     $form->loadDataFrom($team);
     $form->disableSecurityToken();
     return $form;
 }
Example #16
0
 /**
  * Builds an item edit form.  The arguments to getCMSFields() are the popupController and
  * popupFormName, however this is an experimental API and may change.
  * 
  * @todo In the future, we will probably need to come up with a tigher object representing a partially
  * complete controller with gaps for extra functionality.  This, for example, would be a better way
  * of letting Security/login put its log-in form inside a UI specified elsewhere.
  * 
  * @return Form 
  */
 function ItemEditForm()
 {
     if (empty($this->record)) {
         $controller = Controller::curr();
         $noActionURL = $controller->removeAction($_REQUEST['url']);
         $controller->getResponse()->removeHeader('Location');
         //clear the existing redirect
         return $controller->redirect($noActionURL, 302);
     }
     $actions = new FieldList();
     if ($this->record->ID !== 0) {
         $actions->push(FormAction::create('doSave', _t('GridFieldDetailForm.Save', 'Save'))->setUseButtonTag(true)->addExtraClass('ss-ui-action-constructive')->setAttribute('data-icon', 'accept'));
         $actions->push(FormAction::create('doDelete', _t('GridFieldDetailForm.Delete', 'Delete'))->addExtraClass('ss-ui-action-destructive'));
     } else {
         // adding new record
         //Change the Save label to 'Create'
         $actions->push(FormAction::create('doSave', _t('GridFieldDetailForm.Create', 'Create'))->setUseButtonTag(true)->addExtraClass('ss-ui-action-constructive')->setAttribute('data-icon', 'add'));
         // Add a Cancel link which is a button-like link and link back to one level up.
         $curmbs = $this->Breadcrumbs();
         if ($curmbs && $curmbs->count() >= 2) {
             $one_level_up = $curmbs->offsetGet($curmbs->count() - 2);
             $cancelText = _t('GridFieldDetailForm.CancelBtn', 'Cancel');
             $text = "\r\n\t\t\t\t<a class=\"crumb ss-ui-button ss-ui-action-destructive cms-panel-link ui-corner-all\" href=\"" . $one_level_up->Link . "\">\r\n\t\t\t\t\t{$cancelText}\r\n\t\t\t\t</a>";
             $actions->push(new LiteralField('cancelbutton', $text));
         }
     }
     $fk = $this->gridField->getList()->foreignKey;
     $this->record->{$fk} = $this->gridField->getList()->foreignID;
     $form = new Form($this, 'ItemEditForm', $this->record->getCMSFields(), $actions, $this->component->getValidator());
     $form->loadDataFrom($this->record);
     // TODO Coupling with CMS
     $toplevelController = $this->getToplevelController();
     if ($toplevelController && $toplevelController instanceof LeftAndMain) {
         // Always show with base template (full width, no other panels),
         // regardless of overloaded CMS controller templates.
         // TODO Allow customization, e.g. to display an edit form alongside a search form from the CMS controller
         $form->setTemplate('LeftAndMain_EditForm');
         $form->addExtraClass('cms-content cms-edit-form center ss-tabset');
         $form->setAttribute('data-pjax-fragment', 'CurrentForm Content');
         if ($form->Fields()->hasTabset()) {
             $form->Fields()->findOrMakeTab('Root')->setTemplate('CMSTabSet');
         }
         if ($toplevelController->hasMethod('Backlink')) {
             $form->Backlink = $toplevelController->Backlink();
         } elseif ($this->popupController->hasMethod('Breadcrumbs')) {
             $parents = $this->popupController->Breadcrumbs(false)->items;
             $form->Backlink = array_pop($parents)->Link;
         } else {
             $form->Backlink = $toplevelController->Link();
         }
     }
     $cb = $this->component->getItemEditFormCallback();
     if ($cb) {
         $cb($form, $this);
     }
     return $form;
 }
 /**
  * This form is exactly like the CMS form.  It gives us an opportunity to test the fields outside of the CMS context
  */
 function Form()
 {
     $fields = $this->getCMSFields();
     $actions = new FieldList(new FormAction("save", "Save"), $gohome = new FormAction("gohome", "Go home"));
     $gohome->setAttribute('src', 'frameworktest/images/test-button.png');
     $form = new Form($this, "Form", $fields, $actions);
     $form->loadDataFrom($this->dataRecord);
     return $form;
 }
 function FlashForm()
 {
     Requirements::javascript(THIRDPARTY_DIR . "/behaviour.js");
     Requirements::javascript(EXTERNALCONTENT . "/javascript/external_tiny_mce_improvements.js");
     Requirements::javascript(THIRDPARTY_DIR . '/SWFUpload/SWFUpload.js');
     Requirements::javascript(CMS_DIR . '/javascript/Upload.js');
     $form = new Form($this->controller, "{$this->name}/FlashForm", new FieldSet(new LiteralField('Heading', '<h2><img src="cms/images/closeicon.gif" alt="' . _t('HtmlEditorField.CLOSE', 'close') . '" title="' . _t('HtmlEditorField.CLOSE', 'close') . '" />' . _t('HtmlEditorField.FLASH', 'Flash') . '</h2>'), new TreeDropdownField("FolderID", _t('HtmlEditorField.FOLDER'), "Folder"), new TextField('getflashSearch', _t('HtmlEditorField.SEARCHFILENAME', 'Search by file name')), new ThumbnailStripField("Flash", "FolderID", "getflash"), new FieldGroup(_t('HtmlEditorField.IMAGEDIMENSIONS', "Dimensions"), new TextField("Width", _t('HtmlEditorField.IMAGEWIDTHPX', "Width"), 100), new TextField("Height", "x " . _t('HtmlEditorField.IMAGEHEIGHTPX', "Height"), 100))), new FieldSet(new FormAction("insertflash", _t('HtmlEditorField.BUTTONINSERTFLASH', 'Insert Flash'))));
     $form->loadDataFrom($this);
     return $form;
 }
Example #19
0
 /**
  * @return mixed
  * The contact us form
  */
 public function ContactForm()
 {
     $fields = FieldList::create(TextField::create('Name', _t('Contact.Name', 'Name')), TextField::create('Email', _t('Contact.Email', 'Email')), TextField::create('Phone', _t('Contact.Phone', 'Phone Number')), TextField::create('Subject', _t('Contact.Subject', 'Subject')), TextareaField::create('Message', _t('Contact.Message', 'Message')));
     $actions = FieldList::create(FormAction::create('Submit', _t('Contact.Submit', 'Submit')));
     $required = RequiredFields::create('Name', 'Email', 'Message');
     $form = new Form($this, __FUNCTION__, $fields, $actions, $required);
     if (Session::get('Contact')) {
         $form->loadDataFrom(Session::get('Contact'));
     }
     return $form;
 }
Example #20
0
 public function testLoadDataFromObject()
 {
     $article = $this->objFromFixture('CheckboxSetFieldTest_Article', 'articlewithouttags');
     $articleWithTags = $this->objFromFixture('CheckboxSetFieldTest_Article', 'articlewithtags');
     $tag1 = $this->objFromFixture('CheckboxSetFieldTest_Tag', 'tag1');
     $tag2 = $this->objFromFixture('CheckboxSetFieldTest_Tag', 'tag2');
     $field = new CheckboxSetField("Tags", "Test field", DataObject::get("CheckboxSetFieldTest_Tag")->map());
     $form = new Form(new Controller(), 'Form', new FieldList($field), new FieldList());
     $form->loadDataFrom($articleWithTags);
     $this->assertEquals(array($tag1->ID => $tag1->ID, $tag2->ID => $tag2->ID), $field->Value(), 'CheckboxSetField loads data from a manymany relationship in an object through Form->loadDataFrom()');
 }
Example #21
0
 public function Form()
 {
     $fields = FieldList::create(CompositeField::create(array(TextField::create('FirstName', 'First Name')->addExtraClass('col-sm-6 col-xs-12'), TextField::create('LastName', 'Last Name')->addExtraClass('col-sm-6 col-xs-12'), TextField::create('Email', 'Email Address')->addExtraClass('col-sm-6 col-xs-12'), TextField::create('Contact', 'Contact Number')->addExtraClass('col-sm-6 col-xs-12'), TextField::create('CallingTime', 'Best Calling Time')->addExtraClass('col-sm-6 col-xs-12'), TextField::create('LiquidCapital', 'Liquid Capital')->addExtraClass('col-sm-6 col-xs-12'), DateField::create('TimeStart', 'Time Frame to Start')->setConfig('showcalendar', 'true')->addExtraClass('col-sm-6 col-xs-12')))->addExtraClass('info'), CompositeField::create(array(TextareaField::create('Area', 'In what area are you looking to invest in a franchise?')->addExtraClass('col-sm-12'), TextareaField::create('Experience', 'Business & Relevant Experience')->addExtraClass('col-sm-12'), TextareaField::create('Hear', 'How did you hear about the Beard Papa’s franchise')->addExtraClass('col-sm-12'), TextareaField::create('Message', 'Message')->addExtraClass('col-sm-12')))->addExtraClass('questions'));
     $actions = FieldList::create(FormAction::create('Send', 'Send')->addExtraClass('btn btn-primary'));
     $requires = RequiredFields::create('FirstName', 'LastName', 'Email', 'Contact', 'CallingTime', 'LiquidCapital', 'TimeStart', 'Area', 'Experience', 'Hear');
     $form = new Form($this, __FUNCTION__, $fields, $actions, $requires);
     if ($formData = Session::get('FranchiseData')) {
         $form->loadDataFrom($formData);
     }
     return $form;
 }
Example #22
0
 public function DefaultAddressForm()
 {
     $addresses = $this->member->AddressBook()->sort('Created', 'DESC');
     if ($addresses->exists()) {
         $fields = new FieldList(DropdownField::create("DefaultShippingAddressID", _t("Address.ShippingAddress", "Shipping Address"), $addresses->map('ID', 'toString')->toArray()), DropdownField::create("DefaultBillingAddressID", _t("Address.BillingAddress", "Billing Address"), $addresses->map('ID', 'toString')->toArray()));
         $actions = new FieldList(new FormAction("savedefaultaddresses", _t("Address.SaveDefaults", "Save Defaults")));
         $form = new Form($this, "DefaultAddressForm", $fields, $actions);
         $form->loadDataFrom($this->member);
         return $form;
     }
     return false;
 }
Example #23
0
 public function Form()
 {
     $fields = FieldList::create(TextField::create('Name', 'Name')->addExtraClass('col-sm-12 col-xs-12'), TextField::create('Email', 'Email')->addExtraClass('col-sm-12 col-xs-12'), TextField::create('Subject', 'Subject')->addExtraClass('col-sm-12 col-xs-12'), TextareaField::create('Message', 'Message')->addExtraClass('col-sm-12 col-xs-12'));
     $actions = FieldList::create(FormAction::create('Send', 'Send')->addExtraClass('btn btn-primary'));
     $requires = RequiredFields::create('Name', 'Email', 'Subject', 'Message');
     $form = new Form($this, __FUNCTION__, $fields, $actions, $requires);
     $form->addExtraClass('col-sm-10 col-sm-offset-1 col-xs-12');
     if ($formData = Session::get('ContactData')) {
         $form->loadDataFrom($formData);
     }
     return $form;
 }
Example #24
0
 /**
  * Relation auto-setting is now the only option
  */
 function testAutoRelationSettingOn()
 {
     $o = new TableFieldTest_Object();
     $o->write();
     $tf = new TableField('HasManyRelations', 'TableFieldTest_HasManyRelation', array('Value' => 'Value'), array('Value' => 'TextField'));
     // Test with auto relation setting
     $form = new Form(new TableFieldTest_Controller(), "Form", new FieldList($tf), new FieldList());
     $form->loadDataFrom($o);
     $tf->setValue(array('new' => array('Value' => array('one', 'two'))));
     $form->saveInto($o);
     $this->assertEquals(2, $o->HasManyRelations()->Count());
 }
 function EditForm()
 {
     $member = Member::currentUser();
     if ($member) {
         list($fields, $requiredFields) = MerchantAdminDOD::get_edit_fields();
         $actions = new FieldSet(new FormAction('save', _t('MerchantAdminAccountPage_Controller.SAVE_DETAILS', 'Save Details')));
         $form = new Form($this, 'EditForm', $fields, $actions, $requiredFields);
         $form->loadDataFrom($member);
         $form->dataFieldByName("Password")->setValue("");
         return $form;
     }
 }
 public function Form()
 {
     $record = $this->getSignatureRecord();
     $fields = new FieldList(array(new FieldGroup('Personal Details', array(new TextField('Name', 'Name *', null, 255), new TextField('Position', 'Position', null, 255))), new FieldGroup('Contact Details', array(TextField::create('DirectDial', 'DDI', null, 20)->setAttribute('placeholder', '+64 9 000 0000'), TextField::create('Mobile', 'Mobile', null, 20)->setAttribute('placeholder', '+64 21 000 0000'), new EmailField('Email', 'Email *', null, 255))), new FieldGroup('Options', array(new OptionsetField('Format', 'Output Format *', array('html' => 'HTML', 'txt' => 'Plain Text', 'outlook' => 'Outlook Package'), 'html')))));
     $validator = new RequiredFields('Name', 'Email', 'Format');
     $actions = new FieldList(new FormAction('preview', 'Preview'), new FormAction('download', 'Download'));
     $form = new Form($this, 'Form', $fields, $actions, $validator);
     if ($record) {
         $form->loadDataFrom($record);
     }
     return $form;
 }
 function PopupForm()
 {
     $form = new Form($this, "{$this->name}/PopupForm", new FieldList($headerWrap = new CompositeField(new LiteralField('Heading', sprintf('<h3 class="htmleditorfield-mediaform-heading insert">%s</h3>', 'Edit Source'))), $codeField = new CodeEditorField('TinyMCESource', '')), new FieldList(ResetFormAction::create('cancel', 'Cancel')->addExtraClass('ss-ui-action-destructive')->setUseButtonTag(true), FormAction::create('update', 'Update')->addExtraClass('ss-ui-action-constructive')->setAttribute('data-icon', 'accept')->setUseButtonTag(true)));
     $headerWrap->addExtraClass('CompositeField composite cms-content-header nolabel ');
     //	$contentComposite->addExtraClass('tinymce-codeeditor-field content');
     $codeField->addExtraClass('nolabel stacked');
     $form->unsetValidator();
     $form->loadDataFrom($this);
     $form->addExtraClass('htmleditorfield-form htmleditorfield-codeform cms-dialog-content');
     //	$this->extend('updateLinkForm', $form);
     return $form;
 }
 /**
  * Return a form which sends the user to the first results page. If you want
  * to customize this form, use your own extension and apply that to the
  * page.
  *
  * @return Form
  */
 public function getGoogleSiteSearchForm()
 {
     if ($page = GoogleSiteSearchPage::get()->first()) {
         $label = Config::inst()->get('GoogleSiteSearchDefaultFormExtension', 'submit_button_label');
         $formLabel = Config::inst()->get('GoogleSiteSearchDefaultFormExtension', 'input_label');
         $form = new Form($this, 'GoogleSiteSearchForm', new FieldList(new TextField('Search', $formLabel)), new FieldList(new FormAction('doSearch', $label)));
         $form->setFormMethod('GET');
         $form->setFormAction($page->Link());
         $form->disableSecurityToken();
         $form->loadDataFrom($_GET);
         return $form;
     }
 }
 public function Form()
 {
     $record = $this->record;
     $fields = $record->getCMSFields();
     $validator = $record->hasMethod('getValidator') ? $record->getValidator() : null;
     $save = FormAction::create('doSave', 'Save');
     $save->addExtraClass('ss-ui-button ss-ui-action-constructive')->setAttribute('data-icon', 'accept')->setUseButtonTag(true);
     $form = new Form($this, 'Form', $fields, new FieldList($save), $validator);
     if ($record && $record instanceof DataObject && $record->exists()) {
         $form->loadDataFrom($record);
     }
     return $form;
 }
 /**
  * Handles validating the final step and writing the tickets data to the
  * registration object.
  */
 public function finish($data, $form)
 {
     parent::finish($data, $form);
     $step = $this->getCurrentStep();
     $datetime = $this->getController()->getDateTime();
     $registration = $this->session->getRegistration();
     $ticketsStep = $this->getSavedStepByClass('EventRegisterTicketsStep');
     $tickets = $ticketsStep->loadData();
     // Check that the requested tickets are still available.
     if (!$this->validateTickets($tickets['Tickets'], $form)) {
         Session::set("FormInfo.{$form->FormName()}.data", $form->getData());
         Director::redirectBack();
         return false;
     }
     // Validate the final step.
     if (!$step->validateStep($data, $form)) {
         Session::set("FormInfo.{$form->FormName()}.data", $form->getData());
         Director::redirectBack();
         return false;
     }
     // Reload the first step fields into a form, then save it into the
     // registration object.
     $ticketsStep->setForm($form);
     $fields = $ticketsStep->getFields();
     $form = new Form($this, '', $fields, new FieldSet());
     $form->loadDataFrom($tickets);
     $form->saveInto($registration);
     if ($member = Member::currentUser()) {
         $registration->Name = $member->getName();
         $registration->Email = $member->Email;
     }
     $registration->TimeID = $datetime->ID;
     $registration->MemberID = Member::currentUserID();
     $total = $ticketsStep->getTotal();
     $registration->Total->setCurrency($total->getCurrency());
     $registration->Total->setAmount($total->getAmount());
     foreach ($tickets['Tickets'] as $id => $quantity) {
         if ($quantity) {
             $registration->Tickets()->add($id, array('Quantity' => $quantity));
         }
     }
     $registration->write();
     $this->session->delete();
     // If the registrations is already valid, then send a details email.
     if ($registration->Status == 'Valid') {
         EventRegistrationDetailsEmail::factory($registration)->send();
     }
     $this->extend('onRegistrationComplete', $registration);
     return Director::redirect(Controller::join_links($datetime->Event()->Link(), 'registration', $registration->ID, '?token=' . $registration->Token));
 }