/** * @return FieldSet */ public function getCMSFields() { $fields = parent::getCMSFields(); $fields->addFieldToTab('Root.FormOptions', CheckboxField::create('ShowSubmittedList', 'Show the list of this user\'s submissions')); $fields->addFieldToTab('Root.FormOptions', CheckboxField::create('ShowDraftList', 'Show the list of this user\'s draft submissions')); $fields->addFieldToTab('Root.FormOptions', new CheckboxField('AllowEditingComplete', 'Allow "Complete" submissions to be re-edited')); $fields->addFieldToTab('Root.FormOptions', new CheckboxField('ShowSubmitButton', 'Show the submit button - if not checked, forms will be "submitted" as soon as all required fields are complete')); $fields->addFieldToTab('Root.FormOptions', new TextField('SubmitWarning', 'A warning to display to users when the submit button is clicked')); $fields->addFieldToTab('Root.FormOptions', new CheckboxField('ShowPreviewButton', 'Show the buttons to preview the form')); $fields->addFieldToTab('Root.FormOptions', new CheckboxField('ShowDeleteButton', 'Show the button to delete this form submission')); $fields->addFieldToTab('Root.FormOptions', new CheckboxField('ShowButtonsOnTop', 'Show the form action buttons above the form as well as below')); $fields->addFieldToTab('Root.FormOptions', new CheckboxField('LoadLastSubmission', 'Automatically load the latest incomplete submission when a user visits the form')); $formFields = $this->Fields(); $options = array(); foreach ($formFields as $editableField) { $options[$editableField->Name] = $editableField->Title; } $fields->addFieldToTab('Root.FormOptions', $df = DropdownField::create('SubmissionTitleField', 'Title field to use for new submissions', $options)); $df->setEmptyString('-- field --'); $df->setRightTitle('Useful if submissions are to be listed somewhere and a sort field is required'); if (class_exists('WorkflowDefinition')) { $definitions = WorkflowDefinition::get()->map(); $field = DropdownField::create('WorkflowID', 'Submission workflow', $definitions)->setEmptyString('-- select a workflow --'); $field->setRightTitle('Workflow to use for making a submission complete'); $fields->addFieldToTab('Root.FormOptions', $field); } return $fields; }
/** * CMS Fields * @return FieldList */ public function getCMSFields() { $fields = parent::getCMSFields(); $fields->addFieldsToTab("Root.Main", array(DropdownField::create('FormPageID', 'Select a page', UserDefinedForm::get()->map('ID', 'Title')))); $this->extend('updateCMSFields', $fields); return $fields; }
public function updateDynamicListCMSFields($fields) { // Make sure the draft records are being looked at. $stage = Versioned::current_stage(); Versioned::reading_stage('Stage'); $used = EditableFormField::get()->filter(array('ClassName:PartialMatch' => 'DynamicList')); // Determine whether this dynamic list is being used anywhere. $found = array(); foreach ($used as $field) { // This information is stored using a serialised list, therefore we need to iterate through. if ($field->getSetting('ListTitle') === $this->owner->Title) { // Make sure there are no duplicates recorded. if (!isset($found[$field->ParentID]) && ($form = UserDefinedForm::get()->byID($field->ParentID))) { $found[$field->ParentID] = "<a href='{$form->CMSEditLink()}'>{$form->Title}</a>"; } } } // Display whether there were any dynamic lists found on user defined forms. if (count($found)) { $fields->removeByName('UsedOnHeader'); $fields->addFieldToTab('Root.Main', HeaderField::create('UsedOnHeader', 'Used On', 5)); } $display = count($found) ? implode('<br>', $found) : 'This dynamic list is <strong>not</strong> used.'; $fields->removeByName('UsedOn'); $fields->addFieldToTab('Root.Main', LiteralField::create('UsedOn', '<div>' . $display . '</div>')); Versioned::reading_stage($stage); }
public function onBeforeWrite() { if ($this->MapEmbedHTML) { $this->MapEmbedHTML = preg_replace('/\\s(width|style|height|frameborder)=".*?"/i', '', $this->MapEmbedHTML); } return parent::onBeforeWrite(); }
function testGetFormFields() { // generating the fieldset of fields $form = $this->objFromFixture('UserDefinedForm', 'basic-form-page'); $controller = new UserDefinedFormControllerTest_Controller($form); $fields = $controller->getFormFields(); $this->assertEquals($fields->Count(), 1); // custom error message on a form field $requiredForm = $this->objFromFixture('UserDefinedForm', 'validation-form'); $controller = new UserDefinedFormControllerTest_Controller($requiredForm); UserDefinedForm::$required_identifier = "*"; $fields = $controller->getFormFields(); $this->assertEquals($fields->First()->getCustomValidationMessage()->getValue(), 'Custom Error Message'); $this->assertEquals($fields->First()->Title(), 'Required Text Field <span class=\'required-identifier\'>*</span>'); // test custom right title $field = $form->Fields()->First(); $field->setSetting('RightTitle', 'Right Title'); $field->write(); $controller = new UserDefinedFormControllerTest_Controller($form); $fields = $controller->getFormFields(); $this->assertEquals($fields->First()->RightTitle(), "Right Title"); // test empty form $emptyForm = $this->objFromFixture('UserDefinedForm', 'empty-form'); $controller = new UserDefinedFormControllerTest_Controller($emptyForm); $this->assertFalse($controller->Form()); }
function getCMSFields() { $fields = parent::getCMSFields(); $fields->addFieldToTab('Root.Image Upload', $uploadHeroField = UploadField::create('ContactImage', 'Please upload an image to be displayed on your Contact Page. ')->setDescription('We recommend a <strong>360x482</strong> image.')); $uploadHeroField->setFolderName('Contact'); $uploadHeroField->setAllowedFileCategories('image'); return $fields; }
function getCMSFields() { $fields = parent::getCMSFields(); // Main Tab $fields->addFieldsToTab('Root.Main', array(HTMLEditorField::create('ExtraContent', 'Extra Content Area')), 'Metadata'); // Google Map $fields->addFieldsToTab('Root.GoogleMap', array(TextField::create('GoogleMap', 'Google Map URL'))); return $fields; }
function getCMSFields() { $fields = parent::getCMSFields(); // Main Tab $fields->addFieldsToTab('Root.Main', array(HTMLEditorField::create('ExtraContent', 'Extra Content Area')), 'Metadata'); $fields->addFieldsToTab('Root.Phone', array(GridField::create('Phones', 'Current phone number(s)', $this->Phones(), GridFieldConfig_RelationEditor::create()->removeComponentsByType('GridFieldAddNewButton')->addComponent(new GridFieldEditableColumns())->addComponent(new GridFieldDeleteAction())->addComponent(new GridFieldAddNewInlineButton())->addComponent(new GridFieldOrderableRows())))); // Google Map $fields->addFieldsToTab('Root.GoogleMap', array(TextField::create('GoogleMap', 'Google Map URL'))); return $fields; }
public function getCMSFields() { $fields = parent::getCMSFields(); $gateways = GatewayInfo::get_supported_gateways(); $amountfields = $this->Fields()->map("ID", "Title"); $fields->addFieldsToTab("Root.Payment", array(DropdownField::create("PaymentAmountFieldID", "Payment Amount Field", $amountfields)->setDescription("This must return a value like 20.00 (no dollar sign)"), new DropdownField("PaymentGateway", "Payment Gateway", $gateways), new TextField("PaymentCurrency", "Payment Currency"), new CheckboxField("PaymentFields_Card", "Show Card Fields"), new CheckboxField("PaymentFields_Billing", "Show Billing Fields"), new CheckboxField("PaymentFields_Shipping", "Show Shipping Fields"), new CheckboxField("PaymentFields_Company", "Show Company Fields"), new CheckboxField("PaymentFields_Email", "Show Email Fields"))); // text to show on error $onErrorFieldSet = new CompositeField($label = new LabelField('OnErrorMessageLabel', _t('UserDefinedForm.ONERRORLABEL', 'Show on error')), $editor = new HtmlEditorField("OnErrorMessage", "", _t('UserDefinedForm.ONERRORMESSAGE', $this->OnErrorMessage))); $onErrorFieldSet->addExtraClass('field'); $fields->insertAfter($onErrorFieldSet, "OnCompleteMessage"); return $fields; }
public function getCMSFields() { $fields = parent::getCMSFields(); // Embargo $embargo = ToggleCompositeField::create('Embargo', 'Embargo', array(DateField::create('Starts', 'Allow participation from')->setRightTitle('Optional. If left blank, participation starts when page is published')->setConfig('showcalendar', true), DateField::create('Expires', 'Until')->setRightTitle('Optional. If left blank, participation will end when page is unpublished.')->setConfig('showcalendar', true)))->setStartClosed(false); $fields->addFieldToTab('Root.FormOptions', $embargo, 'SubmitButtonText'); // Reports $config = GridFieldConfig_RecordEditor::create(); $reports = GridField::create('Reports', 'Reports', $this->Reports(), $config); $fields->addFieldToTab('Root.Reports', $reports); return $fields; }
public function customFormActions($isReadonly = false) { $fields = parent::customFormActions($isReadonly); // get the newsletters in the system $newsletterTypes = DataObject::get('NewsletterType'); $availableNewsletters = array(); $nlCheckboxes = array(); foreach ($this->Newsletters() as $subscribeTo) { $availableNewsletters[] = $subscribeTo->ID; } // create a checkbox for each newsletter if ($newsletterTypes && is_object($newsletterTypes)) { foreach ($newsletterTypes as $newsletterType) { $nlCheckboxes[] = new CheckboxField("CustomNewsletters[{$newsletterType->ID}]", $newsletterType->Title, in_array($newsletterType->ID, $availableNewsletters)); } } $fields->push(new OptionsetField('AllNewsletters', '', array(1 => 'All newsletters', 0 => 'Specific newsletters'), $this->AllNewsletters)); $fields->push(new CompositeField($nlCheckboxes)); $fields->push(new TextField('Subject', 'Subject line on confirmation', $this->Subject)); return $fields; }
/** * Gets a list of email templates suitable for populating the email template dropdown. * * @return array */ public function getEmailTemplateDropdownValues() { $templates = array(); $finder = new SS_FileFinder(); $finder->setOption('name_regex', '/^.*\\.ss$/'); $found = $finder->find(BASE_PATH . '/' . UserDefinedForm::config()->email_template_directory); foreach ($found as $key => $value) { $template = pathinfo($value); $templates[$template['filename']] = $template['filename']; } return $templates; }
/** * Get the form fields for the form on this page. Can modify this FieldSet * by using {@link updateFormFields()} on an {@link Extension} subclass which * is applied to this controller. * * @return FieldList */ public function getFormFields() { $fields = new FieldList(); if ($this->Fields()) { foreach ($this->Fields() as $editableField) { // get the raw form field from the editable version $field = $editableField->getFormField(); if (!$field) { break; } // set the error / formatting messages $field->setCustomValidationMessage($editableField->getErrorMessage()); // set the right title on this field if ($right = $editableField->getSetting('RightTitle')) { $field->setRightTitle($right); } // if this field is required add some if ($editableField->Required) { $field->addExtraClass('requiredField'); if ($identifier = UserDefinedForm::config()->required_identifier) { $title = $field->Title() . " <span class='required-identifier'>" . $identifier . "</span>"; $field->setTitle($title); } } // if this field has an extra class if ($editableField->getSetting('ExtraClass')) { $field->addExtraClass(Convert::raw2att($editableField->getSetting('ExtraClass'))); } // set the values passed by the url to the field $request = $this->getRequest(); if ($var = $request->getVar($field->name)) { $field->value = Convert::raw2att($var); } $fields->push($field); } } $this->extend('updateFormFields', $fields); return $fields; }
public function nonProtectedGetFormParent() { $formID = $this->owner->FormID ? $this->owner->FormID : Session::get('CMSMain.currentPage'); return UserDefinedForm::get()->byID($formID); }
/** * Import Gravity Form as User Defined Form */ public function importGravityForms() { if (!class_exists('UserFormFieldEditorExtension')) { throw new WordpressImportException(__FUNCTION__ . ' requires User Defined Forms 3.0+'); } //$list = ElementContent::get()->filter(array('HTML:PartialMatch' => '[gravityform')); // Get existing gravity form items $existingWpRecords = array(); $list = $this->applyWordpressFilter(UserDefinedForm::get(), array('posts', 'rg_form')); foreach ($list as $record) { if (isset($record->WordpressData['gravityform'])) { // Handle case where a Page was the only one using a Gravity Form, so // the gravity form data was just attached to that existing data. $gfData = $record->WordpressData['gravityform']; if (!isset($gfData['id'])) { throw new Exception('Missing "id" in "gravityform" data on #' . $record->ID . ' in its "WordpressData" column.'); } $id = $gfData['id']; $existingWpRecords[$id] = $record; } else { // Handle case where Gravity form was used in multiple locations, wherein // a new page was created. $existingWpRecords[$record->WordpressID] = $record; } } $gfDB = new WordpressGravityForms($this->_db); foreach ($gfDB->getForms() as $gfData) { $gfID = (int) $gfData['id']; if ($existingWpRecords && isset($existingWpRecords[$gfID])) { // Skip existing imported gravity forms $this->log($record, 'nochange'); continue; } $gfMeta = $gfDB->attachAndGetFormMeta($gfData); if (!isset($gfMeta['display_meta']['fields'])) { continue; } // Create array of EditableFormField's $fields = array(); $fieldsData = $gfMeta['display_meta']['fields']; foreach ($fieldsData as $i => $fieldData) { if (!isset($fieldData['type'])) { throw new WordpressImportException('Gravity Form field is missing "type"'); } $type = $fieldData['type']; $label = isset($fieldData['label']) ? $fieldData['label'] : null; $field = null; switch ($type) { case 'textarea': $field = EditableTextField::create(); $field->Rows = 4; break; case 'name': case 'text': case 'phone': $field = EditableTextField::create(); break; case 'email': $field = EditableEmailField::create(); break; case 'number': $field = EditableNumericField::create(); $field->MinValue = isset($fieldData['rangeMin']) ? $fieldData['rangeMin'] : 0; $field->MaxValue = isset($fieldData['rangeMax']) ? $fieldData['rangeMax'] : 0; break; case 'radio': $field = EditableRadioField::create(); break; case 'checkbox': $choices = isset($fieldData['choices']) ? $fieldData['choices'] : false; if (!$choices) { throw new WordpressImportException('Cannot find "choices" on ' . $type); } if (count($choices) == 1) { $field = EditableCheckbox::create(); foreach ($choices as $choiceData) { $label = $choiceData['text']; break; } } else { $field = EditableCheckboxGroupField::create(); } break; case 'select': $field = EditableDropdown::create(); break; case 'captcha': // No Captcha field comes with User Defined Forms. $field = false; break; case 'html': // Ignore literal field $field = EditableLiteralField::create(); $field->Content = isset($fieldData['content']) ? $fieldData['content'] : ''; break; default: //Debug::dump($fieldData); throw new WordpressImportException('Gravity Form field is unhandled type "' . $type . '".'); break; } if ($field === null) { throw new WordpressImportException('Gravity Form field is mishandled type "' . $type . '" $field isn\'t set.'); } if ($field) { /*$descriptionPlacement = isset($fieldData['descriptionPlacement']) ? $fieldData['descriptionPlacement'] : 'above'; if ($descriptionPlacement === 'above') { $field->Title = $label; } else if ($descriptionPlacement === 'below') { $field->RightTitle = $label; } else { throw new WordpressImportException('Invalid "descriptionPlacement" value "'.$descriptionPlacement.'"'); }*/ $field->Title = $label; $field->Placeholder = isset($fieldData['placeholder']) ? $fieldData['placeholder'] : null; $field->CustomErrorMessage = isset($fieldData['errorMessage']) ? $fieldData['errorMessage'] : null; $field->Required = isset($fieldData['isRequired']) ? $fieldData['isRequired'] : false; $field->Sort = $i + 1; $choices = isset($fieldData['choices']) ? $fieldData['choices'] : false; if ($choices && $field->hasMethod('Options')) { foreach ($choices as $choiceData) { $choice = EditableOption::create(); $choice->Title = $choiceData['value']; $field->Options()->add($choice); } } $fields[] = $field; } } // Get existing page record if only a single page is using a gravity form. $oneGravityFormPageRecord = null; $pageContent = null; if (isset($this->_classes_using_elemental['SiteTree']) || isset($this->_classes_using_elemental['Page'])) { $list = ElementContent::get()->filter(array('HTML:PartialMatch' => '[gravityform id="' . $gfID . '"')); $list = $list->toArray(); if (count($list) == 1) { $elementContent = $list[0]; $oneGravityFormPageRecord = $elementContent->Parent(); $pageContent = $elementContent->HTML; } } else { $list = SiteTree::get()->filter(array('Content:PartialMatch' => '[gravityform id="' . $gfID . '"')); $list = $list->toArray(); if (count($list) == 1) { $oneGravityFormPageRecord = $list[0]; $pageContent = $oneGravityFormPageRecord->Content; } } if (substr_count($pageContent, '[gravityform') > 1) { // If two gravity forms exist on the single page, don't make it write the UserDefinedForm // to an existing page. $oneGravityFormPageRecord = null; } /*if ($oneGravityFormPageRecord && $existingWpRecords && isset($existingWpRecords[$oneGravityFormPageRecord->WordpressID])) { // Skip existing imported gravity forms $this->log($record, 'nochange'); continue; }*/ // Create UDF if ($oneGravityFormPageRecord) { // If only one page is using a Gravity Form, transform it into a UserDefinedForm page. $record = $oneGravityFormPageRecord->newClassInstance('UserDefinedForm'); $wordpressData = $record->WordpressData; $wordpressData['gravityform'] = $gfData; $record->WordpressData = $wordpressData; } else { // If multiple pages are using the same Gravity Form, just create the UserDefinedForm page. $record = UserDefinedForm::create(); if (!isset($gfData['title'])) { throw new WordpressImportException('Gravity Form missing "title" field.'); } $record->Title = $gfData['title']; if (!isset($gfData['date_created'])) { throw new WordpressImportException('Gravity Form missing "date_created" field.'); } $record->Created = $gfData['date_created']; $record->WordpressData = $gfData; } foreach ($fields as $field) { $record->Fields()->add($field); } //Debug::dump($record->toMap()); try { $isPublished = isset($gfData['is_active']) && $gfData['is_active'] || $record->isPublished(); $this->writeAndPublishRecord($record, $isPublished); } catch (Exception $e) { $this->log($record, 'error', $e); throw $e; } } }
/** * Updates a formfield with the additional metadata specified by this field * * @param FormField $field */ protected function updateFormField($field) { // set the error / formatting messages $field->setCustomValidationMessage($this->getErrorMessage()); // set the right title on this field if ($this->RightTitle) { // Since this field expects raw html, safely escape the user data prior $field->setRightTitle(Convert::raw2xml($this->RightTitle)); } // if this field is required add some if ($this->Required) { // Required validation can conflict so add the Required validation messages as input attributes $errorMessage = $this->getErrorMessage()->HTML(); $field->addExtraClass('requiredField'); $field->setAttribute('data-rule-required', 'true'); $field->setAttribute('data-msg-required', $errorMessage); if ($identifier = UserDefinedForm::config()->required_identifier) { $title = $field->Title() . " <span class='required-identifier'>" . $identifier . "</span>"; $field->setTitle($title); } } // if this field has an extra class if ($this->ExtraClass) { $field->addExtraClass($this->ExtraClass); } }
public function onAfterWrite() { parent::onAfterWrite(); $changedFields = $this->getChangedFields(); // Reset $this->subpagesToPublishIfPublishingThisRecord = array(); // For detecting a change to $SubmissionPageTitleField sp that all child pages can have their title // fields updated to match the $SubmittedFormField.Value $hasChangedSubmissionPageTitleField = false; if (isset($changedFields['SubmissionPageTitleField']) && $changedFields['SubmissionPageTitleField'] && $changedFields['SubmissionPageTitleField']['before'] !== $changedFields['SubmissionPageTitleField']['after'] && $changedFields['SubmissionPageTitleField']['after'] != '') { $hasChangedSubmissionPageTitleField = true; } // For detecting a change to $TemplatePageMarkup so that all child pages have their $Content field // updated to the HTML provided. $hasChangedTemplatePageMarkup = false; if (isset($changedFields['TemplatePageMarkup']) && $changedFields['TemplatePageMarkup'] && $changedFields['TemplatePageMarkup']['before'] !== $changedFields['TemplatePageMarkup']['after']) { $hasChangedTemplatePageMarkup = true; } if ($hasChangedSubmissionPageTitleField || $hasChangedTemplatePageMarkup) { $classes = UserSubmissionExtension::get_classes_extending(); $list = SiteTree::get()->filter(array('ClassName' => $classes, 'ParentID' => $this->ID)); foreach ($list as $record) { $record->updateDBFromSubmission(); if ($record->getChangedFields(true)) { $isVersionedAndLatestPublished = $record->has_extension('Versioned') && !$record->stagesDiffer('Stage', 'Live'); $record->write(); if ($isVersionedAndLatestPublished) { // Only publish subpages that aren't already in a 'Modified' state. $this->subpagesToPublishIfPublishingThisRecord[] = $record; } } } } }