public function getFormFieldFromEditableFormField(EditableFormField $fieldRecord)
 {
     $field = $fieldRecord->getFormField();
     // Remove templates added by EditableFormField
     $field->setFieldHolderTemplate(null);
     $field->setTemplate(null);
     // Simplify dropdown to only have options that are used
     if ($field->hasMethod('getSource')) {
         $source = $field->getSource();
         $availableSources = SubmittedFormField::get()->filter(array('ParentID' => $this->controller->data()->PublishedSubmittedFormIDs(), 'Name' => $fieldRecord->Name, 'Value' => array_keys($source)))->column('Value');
         if (!$availableSources) {
             // Don't show the field if there is nothing to search on.
             return null;
         }
         $newSources = array();
         foreach ($availableSources as $value) {
             if (isset($source[$value])) {
                 $newSources[$value] = $source[$value];
             }
         }
         if (!$newSources) {
             // Don't show the field if there is nothing to search on.
             return null;
         }
         $field->setSource($newSources);
     }
     if ($field->hasMethod('setHasEmptyDefault') && ($dropdownEmptyString = $this->config()->dropdown_empty_string)) {
         // Defaults to '- Please select -', configured above.
         $field->setEmptyString($dropdownEmptyString);
     }
     // Attach EditableFormField to differentiate EditableFormField fields from regular ones
     // in the form.
     $field->EditableFormField = $fieldRecord;
     return $field;
 }
 public function processNext(EditableFormField $field)
 {
     $formField = $field->getFormField();
     if (!$formField) {
         return $this;
     }
     $this->push($formField);
     if ($formField instanceof UserFormsFieldContainer) {
         return $formField->setParent($this);
     }
     return $this;
 }
 function testPublishingNormalField()
 {
     $id = $this->form->ID;
     // test a normal field
     $field = new EditableFormField();
     $field->write();
     $this->form->Fields()->add($field);
     // upon adding it, it shouldn't  be on the live site
     $live = Versioned::get_one_by_stage("UserDefinedForm", "Live", "\"UserDefinedForm_Live\".\"ID\" = {$id}");
     $this->assertFalse($live);
     // upon publishing the field should exist
     $this->form->doPublish();
     $live = Versioned::get_one_by_stage("UserDefinedForm", "Live", "\"UserDefinedForm_Live\".\"ID\" = {$id}");
     $this->assertEquals($live->Fields()->Count(), 1);
 }
 function populateFromPostData($data)
 {
     parent::populateFromPostData($data);
     $fieldSet = $this->Options();
     $deletedOptions = explode(',', $data['Deleted']);
     // store default, etc
     foreach ($fieldSet as $option) {
         if ($deletedOptions && array_search($option->ID, $deletedOptions) !== false) {
             $option->delete();
             continue;
         }
         if ($data[$option->ID]) {
             $option->populateFromPostData($data[$option->ID]);
         }
         unset($data[$option->ID]);
     }
     foreach ($data as $tempID => $optionData) {
         if (!$tempID || !is_array($optionData) || empty($optionData) || !preg_match('/^_?\\d+$/', $tempID)) {
             continue;
         }
         // what will we name the new option?
         $newOption = new EditableCheckboxOption();
         $newOption->Name = 'option' . (string) $optionNumber++;
         $newOption->ParentID = $this->ID;
         $newOption->populateFromPostData($optionData);
     }
 }
 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);
 }
 /**
  * @return FieldList
  */
 public function getCMSFields()
 {
     $this->beforeUpdateCMSFields(function (FieldList $fields) {
         $fields->addFieldToTab('Root.Main', CheckboxField::create('DefaultToToday', _t('EditableFormField.DEFAULTTOTODAY', 'Default to Today?')), 'RightTitle');
     });
     return parent::getCMSFields();
 }
 public function php($data)
 {
     if (!parent::php($data)) {
         return false;
     }
     // Skip unsaved records
     if (empty($data['ID']) || !is_numeric($data['ID'])) {
         return true;
     }
     $fields = EditableFormField::get()->filter('ParentID', $data['ID'])->sort('"Sort" ASC');
     // Current nesting
     $stack = array();
     $conditionalStep = false;
     // Is the current step conditional?
     foreach ($fields as $field) {
         if ($field instanceof EditableFormStep) {
             // Page at top level, or after another page is ok
             if (empty($stack) || count($stack) === 1 && $stack[0] instanceof EditableFormStep) {
                 $stack = array($field);
                 $conditionalStep = $field->DisplayRules()->count() > 0;
                 continue;
             }
             $this->validationError('FormFields', _t("UserFormValidator.UNEXPECTED_BREAK", "Unexpected page break '{name}' inside nested field '{group}'", array('name' => $field->CMSTitle, 'group' => end($stack)->CMSTitle)), 'error');
             return false;
         }
         // Validate no pages
         if (empty($stack)) {
             $this->validationError('FormFields', _t("UserFormValidator.NO_PAGE", "Field '{name}' found before any pages", array('name' => $field->CMSTitle)), 'error');
             return false;
         }
         // Nest field group
         if ($field instanceof EditableFieldGroup) {
             $stack[] = $field;
             continue;
         }
         // Unnest field group
         if ($field instanceof EditableFieldGroupEnd) {
             $top = end($stack);
             // Check that the top is a group at all
             if (!$top instanceof EditableFieldGroup) {
                 $this->validationError('FormFields', _t("UserFormValidator.UNEXPECTED_GROUP_END", "'{name}' found without a matching group", array('name' => $field->CMSTitle)), 'error');
                 return false;
             }
             // Check that the top is the right group
             if ($top->EndID != $field->ID) {
                 $this->validationError('FormFields', _t("UserFormValidator.WRONG_GROUP_END", "'{name}' found closes the wrong group '{group}'", array('name' => $field->CMSTitle, 'group' => $top->CMSTitle)), 'error');
                 return false;
             }
             // Unnest group
             array_pop($stack);
         }
         // Normal field type
         if ($conditionalStep && $field->Required) {
             $this->validationError('FormFields', _t("UserFormValidator.CONDITIONAL_REQUIRED", "Required field '{name}' cannot be placed within a conditional page", array('name' => $field->CMSTitle)), 'error');
             return false;
         }
     }
     return true;
 }
示例#8
0
 function populateFromPostData($data)
 {
     $this->Size = !empty($data['Size']) ? $data['Size'] : 32;
     $this->MinLength = !empty($data['MinLength']) ? $data['MinLength'] : 1;
     $this->MaxLength = !empty($data['MaxLength']) ? $data['MaxLength'] : 32;
     $this->Rows = !empty($data['Rows']) ? $data['Rows'] : 1;
     parent::populateFromPostData($data);
 }
 /**
  * Updates a formfield with the additional metadata specified by this field
  *
  * @param FormField $field
  */
 protected function updateFormField($field)
 {
     parent::updateFormField($field);
     $field->setAttribute('data-rule-email', true);
     if ($this->Placeholder) {
         $field->setAttribute('placeholder', $this->Placeholder);
     }
 }
 /**
  * @return FieldList
  */
 public function getCMSFields()
 {
     $fields = parent::getCMSFields();
     $fields->removeByName('Default');
     $fields->removeByName('Validation');
     $fields->addFieldToTab('Root.Main', DropdownField::create("GroupID", _t('EditableFormField.GROUP', 'Group'), Group::get()->map())->setEmptyString(' '));
     return $fields;
 }
 protected function onAfterDelete()
 {
     parent::onAfterDelete();
     // Delete end
     if (($end = $this->End()) && $end->exists()) {
         $end->delete();
     }
 }
示例#12
0
 public function populateFromPostData($data)
 {
     $fieldPrefix = 'Default-';
     if (empty($data['Default']) && !empty($data[$fieldPrefix . 'Year']) && !empty($data[$fieldPrefix . 'Month']) && !empty($data[$fieldPrefix . 'Day'])) {
         $data['Default'] = $data['Year'] . '-' . $data['Month'] . '-' . $data['Day'];
     }
     parent::populateFromPostData($data);
 }
 protected function onAfterDelete()
 {
     parent::onAfterDelete();
     // Delete group
     if (($group = $this->Group()) && $group->exists()) {
         $group->delete();
     }
 }
 /**
  * @return FieldList
  */
 public function getCMSFields()
 {
     $fields = parent::getCMSFields();
     $fields->removeByName(array('Default', 'Validation', 'RightTitle'));
     $levels = array('1' => '1', '2' => '2', '3' => '3', '4' => '4', '5' => '5', '6' => '6');
     $fields->addFieldsToTab('Root.Main', array(DropdownField::create('Level', _t('EditableFormHeading.LEVEL', 'Select Heading Level'), $levels), CheckboxField::create('HideFromReports', _t('EditableLiteralField.HIDEFROMREPORT', 'Hide from reports?'))));
     return $fields;
 }
 public function migrateSettings($data)
 {
     // Migrate 'Folder' setting to 'FolderID'
     if (isset($data['Folder'])) {
         $this->FolderID = $data['Folder'];
         unset($data['Folder']);
     }
     parent::migrateSettings($data);
 }
示例#16
0
 public function getFieldValidationOptions()
 {
     $fields = parent::getFieldValidationOptions();
     $min = $this->getSetting('MinValue') ? $this->getSetting('MinValue') : '';
     $max = $this->getSetting('MaxValue') ? $this->getSetting('MaxValue') : '';
     $extraFields = new FieldList(new NumericField($this->getSettingName('MinValue'), _t('EditableFormField.MINVALUE', 'Min Value'), $min), new NumericField($this->getSettingName('MaxValue'), _t('EditableFormField.MAXVALUE', 'Max Value'), $max));
     $fields->merge($extraFields);
     return $fields;
 }
 public function migrateSettings($data)
 {
     // Migrate 'Default' setting to 'CheckedDefault'
     if (isset($data['Default'])) {
         $this->CheckedDefault = (bool) $data['Default'];
         unset($data['Default']);
     }
     parent::migrateSettings($data);
 }
示例#18
0
 function getFormField()
 {
     if ($field = parent::getFormField()) {
         return $field;
     }
     return new FileField($this->Name, $this->Title, $this->getField('Default'));
     // TODO We can't use the preview feature because FileIFrameField also shows the "From the file store" functionality
     //return new FileIFrameField( $this->Name, $this->Title, $this->getField('Default') );
 }
 public function getFieldConfiguration()
 {
     $field = parent::getFieldConfiguration();
     $folder = $this->getSetting('Folder') ? $this->getSetting('Folder') : null;
     $tree = UserformsTreeDropdownField::create($this->getSettingName("Folder"), _t('EditableUploadField.SELECTUPLOADFOLDER', 'Select upload folder'), "Folder");
     $tree->setValue($folder);
     $field->push($tree);
     return $field;
 }
 /**
  * Updates a formfield with the additional metadata specified by this field
  *
  * @param FormField $field
  */
 protected function updateFormField($field)
 {
     parent::updateFormField($field);
     if ($this->MinValue) {
         $field->setAttribute('data-rule-min', $this->MinValue);
     }
     if ($this->MaxValue) {
         $field->setAttribute('data-rule-max', $this->MaxValue);
     }
 }
 public function getFieldConfiguration()
 {
     $fields = parent::getFieldConfiguration();
     $min = $this->getSetting('MinLength') ? $this->getSetting('MinLength') : '';
     $max = $this->getSetting('MaxLength') ? $this->getSetting('MaxLength') : '';
     $rows = $this->getSetting('Rows') ? $this->getSetting('Rows') : '1';
     $extraFields = new FieldList(new FieldGroup(_t('EditableTextField.TEXTLENGTH', 'Text length'), new TextField($this->getSettingName('MinLength'), "", $min), new TextField($this->getSettingName('MaxLength'), " - ", $max)), new TextField($this->getSettingName('Rows'), _t('EditableTextField.NUMBERROWS', 'Number of rows'), $rows));
     $fields->merge($extraFields);
     return $fields;
 }
 public function updateCMSFields(FieldList $fields)
 {
     $formID = $this->owner->FormID != 0 ? $this->owner->FormID : Session::get('CMSMain.currentPage');
     $formFields = EditableFormField::get()->filter('ParentID', (int) $formID);
     if ($formFields) {
         $source = $formFields->map('ID', 'Title');
         $fields->push(DropdownField::create('ConditionFieldID', 'Only send this email if the following field', $source)->setEmptyString('Select...'));
         $fields->push(TextField::create('ConditionFieldValue', '...has this value'));
     }
 }
示例#23
0
 /**
  * Return the validation information related to this field. This is 
  * interrupted as a JSON object for validate plugin and used in the 
  * PHP. 
  *
  * @see http://docs.jquery.com/Plugins/Validation/Methods
  * @return array
  */
 public function getValidation()
 {
     $options = parent::getValidation();
     if ($this->getSetting('MinLength')) {
         $options['minlength'] = $this->getSetting('MinLength');
     }
     if ($this->getSetting('MaxLength')) {
         $options['maxlength'] = $this->getSetting('MaxLength');
     }
     return $options;
 }
 function getFieldConfiguration()
 {
     $levels = array('1' => '1', '2' => '2', '3' => '3', '4' => '4', '5' => '5', '6' => '6');
     $level = $this->getSetting('Level') ? $this->getSetting('Level') : 3;
     $options = parent::getFieldConfiguration();
     $options->push(new DropdownField("Fields[{$this->ID}][CustomSettings][Level]", _t('EditableFormHeading.LEVEL', 'Select Heading Level'), $levels, $level));
     if ($this->readonly) {
         $extraFields = $options->makeReadonly();
     }
     return $options;
 }
示例#25
0
 function ExtraOptions()
 {
     $baseName = "Fields[{$this->ID}]";
     $extraFields = new FieldSet(new CheckboxField($baseName . "[SendCopy]", _t('EditableEmailField.SENDCOPY', 'Send copy of submission to this address'), $this->SendCopy));
     foreach (parent::ExtraOptions() as $extraField) {
         $extraFields->push($extraField);
     }
     if ($this->readonly) {
         $extraFields = $extraFields->makeReadonly();
     }
     return $extraFields;
 }
 public function getFieldConfiguration()
 {
     $zoomLevels = array();
     for ($i = 1; $i < 20; $i++) {
         $message = $i == 1 ? _t('EditableFormField.LOWEST', 'Lowest') : "";
         $message = $i == 19 ? _t('EditableFormField.HIGHEST', 'Highest') : $message;
         $zoomLevels[$i] = $message ? $i . ' - ' . $message : $i;
     }
     $fields = parent::getFieldConfiguration();
     $fields->merge(new FieldSet(new TextField("Fields[{$this->ID}][CustomSettings][StartLant]", _t('EditableFormField.STARTLATITUDE', 'Starting Point Latitude'), $this->getSetting('StartLant') ? $this->getSetting('StartLant') : '10'), new TextField("Fields[{$this->ID}][CustomSettings][StartLong]", _t('EditableFormField.STARTLONGITUDE', 'Starting Point Longitude'), $this->getSetting('StartLong') ? $this->getSetting('StartLong') : '10'), new DropdownField("Fields[{$this->ID}][CustomSettings][StartZoom]", _t('EditableFormField.STARTZOOM', 'Starting Zoom Level'), $zoomLevels, $this->getSetting('StartZoom') ? $this->getSetting('StartZoom') : '1'), new TextField("Fields[{$this->ID}][CustomSettings][MapWidth]", _t('EditableFormField.MAPWIDTH', 'Map Width'), $this->getSetting('MapWidth') ? $this->getSetting('MapWidth') : '300px'), new TextField("Fields[{$this->ID}][CustomSettings][MapHeight]", _t('EditableFormField.MAPHEIGHT', 'Map Height'), $this->getSetting('MapHeight') ? $this->getSetting('MapHeight') : '300px')));
     return $fields;
 }
 function getFieldConfiguration()
 {
     $fields = parent::getFieldConfiguration();
     // eventually replace hard-coded "Fields"?
     $baseName = "Fields[{$this->ID}]";
     $minLength = $this->getSetting('MinLength') ? $this->getSetting('MinLength') : '';
     $maxLength = $this->getSetting('MaxLength') ? $this->getSetting('MaxLength') : '';
     $rows = $this->getSetting('Rows') ? $this->getSetting('Rows') : '1';
     $extraFields = new FieldSet(new FieldGroup(_t('EditableTextField.TEXTLENGTH', 'Text length'), new TextField($baseName . "[CustomSettings][MinLength]", "", $minLength), new TextField($baseName . "[CustomSettings][MaxLength]", " - ", $maxLength)), new TextField($baseName . "[CustomSettings][Rows]", _t('EditableTextField.NUMBERROWS', 'Number of rows'), $rows));
     $fields->merge($extraFields);
     return $fields;
 }
示例#28
0
 public function getFieldConfiguration()
 {
     $levels = array('1' => '1', '2' => '2', '3' => '3', '4' => '4', '5' => '5', '6' => '6');
     $level = $this->getSetting('Level') ? $this->getSetting('Level') : 3;
     $label = _t('EditableFormHeading.LEVEL', 'Select Heading Level');
     $options = parent::getFieldConfiguration();
     $options->push(new DropdownField($this->getSettingName("Level"), $label, $levels, $level));
     if ($this->readonly) {
         $extraFields = $options->makeReadonly();
     }
     $options->push(new CheckboxField($this->getSettingName('HideFromReports'), _t('EditableLiteralField.HIDEFROMREPORT', 'Hide from reports?'), $this->getSetting('HideFromReports')));
     return $options;
 }
 public function getFieldConfiguration()
 {
     $options = parent::getFieldConfiguration();
     $options->push(new CheckboxField("Fields[{$this->ID}][CustomSettings][Default]", 'Standardmässig angekreuzt?', $this->getSetting('Default')));
     $i = 0;
     $loop = $this->getMC('mergevars');
     foreach ($loop as $field) {
         $i++;
         $FieldName = $field['name'];
         $options->push(new TextField("Fields[{$this->ID}][CustomSettings][{$FieldName}]", "Name des Formularfeldes mit " . $FieldName, $this->getSetting($FieldName)));
     }
     return $options;
 }
 public function php($data)
 {
     if (!parent::php($data)) {
         return false;
     }
     // Skip unsaved records
     if (!$this->record || !$this->record->exists()) {
         return true;
     }
     // Skip validation if not required
     if (empty($data['Required'])) {
         return;
     }
     // Skip validation if no rules
     $count = EditableCustomRule::get()->filter('ParentID', $this->record->ID)->count();
     if ($count == 0) {
         return true;
     }
     // Both required = true and rules > 0 should error
     $this->validationError('Required_Error', _t("EditableFormFieldValidator.REQUIRED_ERROR", "Form fields cannot be required and have conditional display rules."), 'error');
     return false;
 }