Ejemplo n.º 1
0
 /**
  * Determine if it is a URL upload or file upload.
  * Upload the file and set file name
  *
  * @param $key
  * @param $value
  */
 public function setAttribute($key, $value)
 {
     if (in_array($key, array_keys($this->fileFields)) && $value) {
         // If valid URL and file exists, download it
         if (filter_var($value, FILTER_VALIDATE_URL)) {
             $headers = @get_headers($value);
             if (strpos($headers[0], '200') || strpos($headers[0], '301') || strpos($headers[0], '302')) {
                 $fileName = pathinfo($value, PATHINFO_FILENAME);
                 $extension = pathinfo($value, PATHINFO_EXTENSION);
                 $fullFileName = join('.', [$fileName, $extension]);
                 $fileField = new FileField($this, $key, $fullFileName);
                 $this->attributes[$key] = $fileField->uploadRemoteFile($value);
             }
         } elseif ($value instanceof UploadedFile) {
             $fileName = str_slug(pathinfo($value->getClientOriginalName(), PATHINFO_FILENAME));
             $extension = $value->getClientOriginalExtension();
             $fullFileName = join('.', [$fileName, $extension]);
             $fileField = new FileField($this, $key, $fullFileName);
             $this->attributes[$key] = $fileField->uploadFile($value);
         } elseif (is_string($value)) {
             $fileName = pathinfo($value, PATHINFO_FILENAME);
             $extension = pathinfo($value, PATHINFO_EXTENSION);
             $fullFileName = join('.', [$fileName, $extension]);
             $fileField = new FileField($this, $key, $fullFileName);
             $this->attributes[$key] = $fileField->copyLocal($value);
         }
     } else {
         parent::setAttribute($key, $value);
     }
 }
    public function __construct($controller, $name, $fields = null, $actions = null, $validator = null)
    {
        if (!$fields) {
            $helpHtml = _t('GroupImportForm.Help1', '<p>Import one or more groups in <em>CSV</em> format (comma-separated values).' . ' <small><a href="#" class="toggle-advanced">Show advanced usage</a></small></p>');
            $helpHtml .= _t('GroupImportForm.Help2', '<div class="advanced">
	<h4>Advanced usage</h4>
	<ul>
	<li>Allowed columns: <em>%s</em></li>
	<li>Existing groups are matched by their unique <em>Code</em> value, and updated with any new values from the 
	imported file</li>
	<li>Group hierarchies can be created by using a <em>ParentCode</em> column.</li>
	<li>Permission codes can be assigned by the <em>PermissionCode</em> column. Existing permission codes are not
	cleared.</li>
	</ul>
</div>');
            $importer = new GroupCsvBulkLoader();
            $importSpec = $importer->getImportSpec();
            $helpHtml = sprintf($helpHtml, implode(', ', array_keys($importSpec['fields'])));
            $fields = new FieldList(new LiteralField('Help', $helpHtml), $fileField = new FileField('CsvFile', _t('SecurityAdmin_MemberImportForm.FileFieldLabel', 'CSV File <small>(Allowed extensions: *.csv)</small>')));
            $fileField->getValidator()->setAllowedExtensions(array('csv'));
        }
        if (!$actions) {
            $action = new FormAction('doImport', _t('SecurityAdmin_MemberImportForm.BtnImport', 'Import from CSV'));
            $action->addExtraClass('ss-ui-button');
            $actions = new FieldList($action);
        }
        if (!$validator) {
            $validator = new RequiredFields('CsvFile');
        }
        parent::__construct($controller, $name, $fields, $actions, $validator);
        $this->addExtraClass('cms');
        $this->addExtraClass('import-form');
    }
Ejemplo n.º 3
0
 public function __construct($controller, $name, $fields = null, $actions = null, $validator = null)
 {
     if (!$fields) {
         $helpHtml = _t('MemberImportForm.Help1', '<p>Import users in <em>CSV format</em> (comma-separated values).' . ' <small><a href="#" class="toggle-advanced">Show advanced usage</a></small></p>');
         $helpHtml .= _t('MemberImportForm.Help2', '<div class="advanced">' . '<h4>Advanced usage</h4>' . '<ul>' . '<li>Allowed columns: <em>%s</em></li>' . '<li>Existing users are matched by their unique <em>Code</em> property, and updated with any new values from ' . 'the imported file.</li>' . '<li>Groups can be assigned by the <em>Groups</em> column. Groups are identified by their <em>Code</em> property, ' . 'multiple groups can be separated by comma. Existing group memberships are not cleared.</li>' . '</ul>' . '</div>');
         $importer = new MemberCsvBulkLoader();
         $importSpec = $importer->getImportSpec();
         $helpHtml = sprintf($helpHtml, implode(', ', array_keys($importSpec['fields'])));
         $fields = new FieldList(new LiteralField('Help', $helpHtml), $fileField = new FileField('CsvFile', _t('SecurityAdmin_MemberImportForm.FileFieldLabel', 'CSV File <small>(Allowed extensions: *.csv)</small>')));
         $fileField->getValidator()->setAllowedExtensions(array('csv'));
     }
     if (!$actions) {
         $action = new FormAction('doImport', _t('SecurityAdmin_MemberImportForm.BtnImport', 'Import from CSV'));
         $action->addExtraClass('ss-ui-button');
         $actions = new FieldList($action);
     }
     if (!$validator) {
         $validator = new RequiredFields('CsvFile');
     }
     parent::__construct($controller, $name, $fields, $actions, $validator);
     Requirements::javascript(FRAMEWORK_DIR . '/thirdparty/jquery-entwine/dist/jquery.entwine-dist.js');
     Requirements::javascript(FRAMEWORK_ADMIN_DIR . '/javascript/MemberImportForm.js');
     $this->addExtraClass('cms');
     $this->addExtraClass('import-form');
 }
Ejemplo n.º 4
0
 public function getFormField()
 {
     $field = new FileField($this->Name, $this->Title);
     if ($this->getSetting('Folder')) {
         $folder = Folder::get()->byId($this->getSetting('Folder'));
         if ($folder) {
             $field->setFolderName(preg_replace("/^assets\\//", "", $folder->Filename));
         }
     }
     return $field;
 }
Ejemplo n.º 5
0
 public function CreateHeatmapForm()
 {
     $includeWatermark = array("1" => "Yes,Include Watermark", "0" => "No,Remove Watermark");
     $fields = new FieldList($imageField = new FileField('OriginalImage', 'Upload an Image File'), new LiteralField('UploadInfo', 'Acceptable images are jpg or png, 500-1600 pixels wide by 500-1200 pixels height.<hr>'), new OptionsetField('IncludeWatermark', 'Include Watermark?', $includeWatermark, 1));
     $imageField->getValidator()->setAllowedExtensions(array('jpg', 'jpeg', 'png'));
     $imageField->setAttribute('class', 'jfilestyle');
     $imageField->setAttribute('data-buttonText', "<img src='themes/attwiz/images/button-create-heatmap-browse.jpg'></img>");
     $imageField->setAttribute('data-placeholder', 'No file selected..');
     // Create action
     $actions = new FieldList($submit = new FormAction('processCreateHeatmap', ''));
     $submit->setAttribute('src', 'themes/attwiz/images/button-create-heatmap-blue-bg.jpg');
     // Create action
     $validator = new RequiredFields('OriginalImage', 'IncludeWatermark');
     return new Form($this, 'CreateHeatmapForm', $fields, $actions, $validator);
 }
Ejemplo n.º 6
0
 public function __construct()
 {
     parent::__construct('goal-edit-form');
     $this->setEnctype(Form::ENCTYPE_MULTYPART_FORMDATA);
     $lang = OW::getLanguage();
     $id = new HiddenField('projectId');
     $id->setRequired(true);
     $this->addElement($id);
     $name = new TextField('name');
     $name->setRequired(true);
     $name->setLabel($lang->text('ocsfundraising', 'name'));
     $this->addElement($name);
     $btnSet = array(BOL_TextFormatService::WS_BTN_IMAGE, BOL_TextFormatService::WS_BTN_VIDEO, BOL_TextFormatService::WS_BTN_HTML);
     $desc = new WysiwygTextarea('description', $btnSet);
     $desc->setRequired(true);
     $sValidator = new StringValidator(1, 50000);
     $desc->addValidator($sValidator);
     $desc->setLabel($lang->text('ocsfundraising', 'description'));
     $this->addElement($desc);
     $category = new Selectbox('category');
     $category->setLabel($lang->text('ocsfundraising', 'category'));
     $list = OCSFUNDRAISING_BOL_Service::getInstance()->getCategoryList();
     if ($list) {
         foreach ($list as $cat) {
             $category->addOption($cat->id, $lang->text('ocsfundraising', 'category_' . $cat->id));
         }
     }
     $this->addElement($category);
     $target = new TextField('target');
     $target->setRequired(true);
     $target->setLabel($lang->text('ocsfundraising', 'target_amount'));
     $this->addElement($target);
     $min = new TextField('min');
     $min->setLabel($lang->text('ocsfundraising', 'min_amount'));
     $min->setValue(1);
     $this->addElement($min);
     $end = new DateField('end');
     $end->setMinYear(date('Y'));
     $end->setMaxYear(date('Y') + 2);
     $end->setLabel($lang->text('ocsfundraising', 'end_date'));
     $this->addElement($end);
     $imageField = new FileField('image');
     $imageField->setLabel($lang->text('ocsfundraising', 'image_label'));
     $this->addElement($imageField);
     $submit = new Submit('edit');
     $submit->setLabel($lang->text('ocsfundraising', 'edit'));
     $this->addElement($submit);
 }
 /**
  * Test different scenarii for a failed upload : an error occured, no files where provided
  */
 public function testUploadMissingRequiredFile()
 {
     $form = new Form(new Controller(), 'Form', new FieldSet($fileField = new FileField('cv', 'Upload your CV')), new FieldSet(), new RequiredFields('cv'));
     // All fields are filled but for some reason an error occured when uploading the file => fails
     $fileFieldValue = array('name' => 'aCV.txt', 'type' => 'application/octet-stream', 'tmp_name' => '/private/var/tmp/phpzTQbqP', 'error' => 1, 'size' => 3471);
     $fileField->setValue($fileFieldValue);
     $this->assertFalse($form->validate(), 'An error occured when uploading a file, but the validator returned true');
     // We pass an empty set of parameters for the uploaded file => fails
     $fileFieldValue = array();
     $fileField->setValue($fileFieldValue);
     $this->assertFalse($form->validate(), 'An empty array was passed as parameter for an uploaded file, but the validator returned true');
     // We pass an null value for the uploaded file => fails
     $fileFieldValue = null;
     $fileField->setValue($fileFieldValue);
     $this->assertFalse($form->validate(), 'A null value was passed as parameter for an uploaded file, but the validator returned true');
 }
 static function display($files)
 {
     $html = "";
     foreach ($files as $file) {
         $html .= FileField::display($file);
     }
     return $html;
 }
Ejemplo n.º 9
0
 function __construct($name, $title = null, $value = null)
 {
     Deprecation::notice('3.0', "Use UploadField with \$myField->allowedExtensions = array('jpg', 'gif', 'png')");
     if (count(func_get_args()) > 3) {
         Deprecation::notice('3.0', 'Use setRightTitle() and setFolderName() instead of constructor arguments');
     }
     parent::__construct($name, $title, $value);
     $this->getValidator()->setAllowedExtensions(array('jpg', 'gif', 'png'));
 }
Ejemplo n.º 10
0
 public function __construct($name, $title = null, $value = null)
 {
     Deprecation::notice('3.0', "SimpleImageField is deprecated. Use UploadField with " . "\$myField->allowedExtensions = array('jpg', 'gif', 'png')", Deprecation::SCOPE_CLASS);
     if (count(func_get_args()) > 3) {
         Deprecation::notice('3.0', 'Use setRightTitle() and setFolderName() instead of constructor arguments', Deprecation::SCOPE_GLOBAL);
     }
     parent::__construct($name, $title, $value);
     $this->getValidator()->setAllowedExtensions(array('jpg', 'gif', 'png'));
 }
 public function getFormField()
 {
     $field = FileField::create($this->Name, $this->EscapedTitle)->setFieldHolderTemplate('UserFormsField_holder')->setTemplate('UserFormsFileField');
     $field->getValidator()->setAllowedExtensions(array_diff(array_filter(Config::inst()->get('File', 'allowed_extensions')), $this->config()->allowed_extensions_blacklist));
     $folder = $this->Folder();
     if ($folder && $folder->exists()) {
         $field->setFolderName(preg_replace("/^assets\\//", "", $folder->Filename));
     }
     $this->doUpdateFormField($field);
     return $field;
 }
 function Form()
 {
     if ($this->request->requestVar('_REDIRECT_BACK_URL')) {
         $url = $this->request->requestVar('_REDIRECT_BACK_URL');
     } else {
         if ($this->request->getHeader('Referer')) {
             $url = $this->request->getHeader('Referer');
         } else {
             $url = Director::baseURL();
         }
     }
     $folder = Folder::find_or_make("ErrorScreenshots");
     $whatDidYouTryDoField = new TextareaField('WhatDidYouTryToDo', 'What did you try to do');
     $whatDidYouTryDoField->setRows(3);
     $whatWentWrongField = new TextareaField('WhatWentWrong', 'What went wrong');
     $whatWentWrongField->setRows(3);
     $screenshotField = new FileField('Screenshot', 'To take a screenshot press the PRT SCR button on your keyboard, then open MS Word or MS Paint and paste the screenshot. Save the file and then attach (upload) the file here.');
     $screenshotField->setFolderName($folder->Name);
     $form = new Form($this, 'Form', new FieldList(new TextField('Name'), new TextField('Email'), new TextField('URL', 'What is the URL of the page the error occured (this is the address shown in the address bar (e.g. http://www.mysite.com/mypage/with/errors/)', $url), $whatDidYouTryDoField, $whatWentWrongField, $screenshotField), new FieldList(new FormAction('senderror', 'Submit Error')), new RequiredFields(array("Email", "Name")));
     return $form;
 }
Ejemplo n.º 13
0
 /**
  * Class constructor
  */
 public function __construct($tpls)
 {
     parent::__construct('edit-template-form');
     $this->setAction(OW::getRouter()->urlFor('VIRTUALGIFTS_CTRL_Admin', 'editTemplate'));
     $single = count($tpls) == 1;
     $this->setEnctype('multipart/form-data');
     $language = OW::getLanguage();
     $giftService = VIRTUALGIFTS_BOL_VirtualGiftsService::getInstance();
     if ($single) {
         $file = new FileField('file');
         $file->setLabel($language->text('virtualgifts', 'gift_image'));
         $this->addElement($file);
         $tpl = $giftService->findTemplateById($tpls[0]);
     }
     $tplId = new HiddenField('tplId');
     $tplId->setRequired(true);
     $tplId->setValue(implode('|', $tpls));
     $this->addElement($tplId);
     if ($giftService->categoriesSetup()) {
         $categories = new Selectbox('category');
         $categories->setLabel($language->text('virtualgifts', 'category'));
         $categories->setOptions($giftService->getCategories());
         if ($single && isset($tpl)) {
             $categories->setValue($tpl->categoryId);
         }
         $this->addElement($categories);
     }
     if (OW::getPluginManager()->isPluginActive('usercredits')) {
         $price = new TextField('price');
         $price->setLabel($language->text('virtualgifts', 'gift_price'));
         if ($single && isset($tpl)) {
             $price->setValue($tpl->price);
         }
         $this->addElement($price);
     }
     // submit
     $submit = new Submit('save');
     $submit->setValue($language->text('virtualgifts', 'btn_save'));
     $this->addElement($submit);
 }
 public function __construct($controller, $name, $fields = null, $actions = null, $validator = null)
 {
     if (!$fields) {
         $helpHtml = _t('ExcelGroupImportForm.Help1', '<p><a href="{link}">Download sample file</a></p>', array('link' => $controller->Link('downloadsample/Group')));
         $helpHtml .= _t('ExcelGroupImportForm.Help2', '<ul>' . '<li>Existing groups are matched by their unique <em>Code</em> value, and updated with any new values from the ' . 'imported file</li>' . '<li>Group hierarchies can be created by using a <em>ParentCode</em> column.</li>' . '<li>Permission codes can be assigned by the <em>PermissionCode</em> column. Existing permission codes are not ' . 'cleared.</li>' . '</ul>');
         $importer = new GroupCsvBulkLoader();
         $importSpec = $importer->getImportSpec();
         $helpHtml = sprintf($helpHtml, implode(', ', array_keys($importSpec['fields'])));
         $extensions = array('csv', 'xls', 'xlsx', 'ods', 'txt');
         $fields = new FieldList(new LiteralField('Help', $helpHtml), $fileField = new FileField('File', _t('ExcelGroupImportForm.FileFieldLabel', 'File <small><br/>(allowed extensions: {extensions})</small>', array('extensions' => implode(', ', $extensions)))));
         $fileField->getValidator()->setAllowedExtensions(array('csv'));
     }
     if (!$actions) {
         $action = new FormAction('doImport', _t('ExcelGroupImportForm.BtnImport', 'Import from file'));
         $action->addExtraClass('ss-ui-button');
         $actions = new FieldList($action);
     }
     if (!$validator) {
         $validator = new RequiredFields('File');
     }
     parent::__construct($controller, $name, $fields, $actions, $validator);
     $this->addExtraClass('cms');
     $this->addExtraClass('import-form');
 }
 public function __construct($controller, $name, $fields = null, $actions = null, $validator = null)
 {
     if (!$fields) {
         $helpHtml = _t('ExcelMemberImportForm.Help1', '<p><a href="{link}">Download sample file</a></p>', array('link' => $controller->Link('downloadsample/Member')));
         $helpHtml .= _t('ExcelMemberImportForm.Help2', '<ul>' . '<li>Existing users are matched by their unique <em>Email</em> property, and updated with any new values from ' . 'the imported file.</li>' . '<li>Groups can be assigned by the <em>Groups</em> column. Groups are identified by their <em>Code</em> property, ' . 'multiple groups can be separated by comma. Existing group memberships are not cleared.</li>' . '</ul>');
         $importer = new MemberCsvBulkLoader();
         $importSpec = $importer->getImportSpec();
         $helpHtml = sprintf($helpHtml, implode(', ', array_keys($importSpec['fields'])));
         $extensions = array('csv', 'xls', 'xlsx', 'ods', 'txt');
         $fields = new FieldList(new LiteralField('Help', $helpHtml), $fileField = new FileField('File', _t('ExcelMemberImportForm.FileFieldLabel', 'File <small><br/>(allowed extensions: {extensions})</small>', array('extensions' => implode(', ', $extensions)))));
         $fileField->getValidator()->setAllowedExtensions(ExcelImportExport::getValidExtensions());
     }
     if (!$actions) {
         $action = new FormAction('doImport', _t('ExcelMemberImportForm.BtnImport', 'Import from file'));
         $action->addExtraClass('ss-ui-button');
         $actions = new FieldList($action);
     }
     if (!$validator) {
         $validator = new RequiredFields('File');
     }
     parent::__construct($controller, $name, $fields, $actions, $validator);
     $this->addExtraClass('cms');
     $this->addExtraClass('import-form');
 }
Ejemplo n.º 16
0
    public function MessageForm($request = null, $itemID = 0)
    {
        if ($itemID == 0) {
            $itemID = isset($_REQUEST['ToMemberID']) ? $_REQUEST['ToMemberID'] : 0;
        }
        $mergeText = "<ul><li>{" . implode("}</li><li>{", PostmarkHelper::MergeTags()) . "}</li></ul>";
        $form = new Form($this, 'MessageForm', new FieldList(array(ObjectSelectorField::create('ToMemberID', 'To:')->setValue($itemID)->setSourceObject(Config::inst()->get('PostmarkAdmin', 'member_class'))->setDisplayField('Email'), DropdownField::create('FromID', 'From')->setSource(PostmarkSignature::get()->filter('IsActive', 1)->map('ID', 'Email')->toArray()), TextField::create('Subject'), QuillEditorField::create('Body'), LiteralField::create('MergeTypes', '<div class="varialbes toggle-block">
					<h4>Merge Values</h4>
					<div class="contents">' . $mergeText . '</div>
				</div>'), HiddenField::create('InReplyToID')->setValue(isset($_REQUEST['ReplyToMessageID']) ? $_REQUEST['ReplyToMessageID'] : 0), FileField::create('Attachment_1', 'Attachment One'), FileField::create('Attachment_2', 'Attachment Two'), FileField::create('Attachment_3', 'Attachment Three'), FileField::create('Attachment_4', 'Attachment Four'), FileField::create('Attachment_5', 'Attachment Five'))), new FieldList(FormAction::create('postmessage', 'Sent Message')));
        $requiredField = new RequiredFields(array('FromID', 'Subject', 'Body'));
        $form->setValidator($requiredField);
        $this->extend('updateMessageForm', $form, $itemID);
        $form->setFormAction($this->Link('PostmarkMessage/MessageForm'));
        return $form;
    }
Ejemplo n.º 17
0
 function __construct($form_name, $name, $title = null, $configuration = array())
 {
     parent::__construct($name, $title);
     if (isset($value)) {
         $this->value = $value;
     }
     SWFUploadConfig::$form_name = $form_name;
     if (!empty($configuration)) {
         SWFUploadConfig::Configure($configuration);
     }
     $url = SWFUploadConfig::get_var('upload_url');
     if (empty($url)) {
         SWFUploadConfig::set_var('upload_url', Director::absoluteURL(Controller::curr()->Link('handleswfupload')));
     }
     SWFUploadConfig::Bootstrap();
 }
 public function setValue($value, $data = null)
 {
     if ($value) {
         $this->processValue($value);
     } elseif ($data) {
         if (is_array($data)) {
             if (isset($data[$this->name])) {
                 $this->processValue($data[$this->name]);
             }
         } else {
             $field = $this->name . 'ID';
             if ($data->{$field}) {
                 $this->fileID = $data->{$field};
             }
         }
     }
     return parent::setValue($value);
 }
Ejemplo n.º 19
0
 public function getFormField()
 {
     $field = FileField::create($this->Name, $this->Title);
     if ($this->getSetting('Folder')) {
         $folder = Folder::get()->byId($this->getSetting('Folder'));
         if ($folder) {
             $field->setFolderName(preg_replace("/^assets\\//", "", $folder->Filename));
         }
     }
     if ($this->Required) {
         // Required validation can conflict so add the Required validation messages
         // as input attributes
         $errorMessage = $this->getErrorMessage()->HTML();
         $field->setAttribute('data-rule-required', 'true');
         $field->setAttribute('data-msg-required', $errorMessage);
     }
     return $field;
 }
 function FoundationForm()
 {
     $fields = new FieldList(HeaderField::create('FormFieldsHeader', 'Form Fields', 3), TextField::create('TextField', 'TextField'), EmailField::create('EmailField', 'EmailField'), PasswordField::create('PasswordField', 'PasswordField'), TextareaField::create('TextareaField', 'TextareaField'), FileField::create('FileField', 'FileField'), CheckboxField::create('CheckboxField', 'CheckboxField'), DropdownField::create('DropdownField', 'DropdownField')->setSource(array('NZ' => 'New Zealand', 'US' => 'United States', 'GEM' => 'Germany'))->setEmptyString(''), CheckboxsetField::create('CheckboxsetField', 'CheckboxsetField')->setSource(array('NZ' => 'New Zealand', 'US' => 'United States', 'GEM' => 'Germany')), OptionsetField::create('OptionsetField', 'OptionsetField')->setSource(array('NZ' => 'New Zealand', 'US' => 'United States', 'GEM' => 'Germany')), HeaderField::create('FieldGroupHeader', 'Field Groups', 3), FieldGroup::create(TextField::create('FieldGroupTextField', 'TextField')->addExtraClass('small-6 columns'), TextField::create('FieldGroupTextField1', 'TextField')->addExtraClass('small-6 columns')), FieldGroup::create(TextField::create('FieldGroupTextField2', 'TextField')->addExtraClass('small-4 columns'), TextField::create('FieldGroupTextField3', 'TextField')->addExtraClass('small-4 columns'), TextField::create('FieldGroupTextField4', 'TextField')->addExtraClass('small-4 columns')), FieldGroup::create(TextField::create('FieldGroupTextField5', 'TextField')->addExtraClass('small-3 columns'), TextField::create('FieldGroupTextField6', 'TextField')->addExtraClass('small-3 columns'), TextField::create('FieldGroupTextField7', 'TextField')->addExtraClass('small-3 columns'), TextField::create('FieldGroupTextField8', 'TextField')->addExtraClass('small-3 columns')), FieldGroup::create(TextField::create('FieldGroupTextField9', 'TextField')->addExtraClass('large-2 small-4 columns'), TextField::create('FieldGroupTextField10', 'TextField')->addExtraClass('large-2 small-4 columns'), TextField::create('FieldGroupTextField11', 'TextField')->addExtraClass('large-2 small-4 columns'), TextField::create('FieldGroupTextField12', 'TextField')->addExtraClass('large-2 small-4 columns'), TextField::create('FieldGroupTextField13', 'TextField')->addExtraClass('large-2 small-4 columns'), TextField::create('FieldGroupTextField14', 'TextField')->addExtraClass('large-2 small-4 columns')), FieldGroup::create(TextField::create('FieldGroupTextField15', 'TextField')->addExtraClass('small-6 columns'), TextField::create('FieldGroupTextField16', 'TextField')->addExtraClass('small-4 columns'), TextField::create('FieldGroupTextField17', 'TextField')->addExtraClass('small-2 columns')), FieldGroup::create(DropdownField::create('DropdownField2', 'DropdownField')->setSource(array('NZ' => 'New Zealand', 'US' => 'United States', 'GEM' => 'Germany'))->addExtraClass('large-6 small-6 columns')->setEmptyString(''), DropdownField::create('DropdownField3', 'DropdownField')->setSource(array('NZ' => 'New Zealand', 'US' => 'United States', 'GEM' => 'Germany'))->addExtraClass('large-6 small-6 columns')->setEmptyString('')), HeaderField::create('SwitchFieldsHeader', 'Switch Fields', 3), FoundationSwitchField::create('SwitchField', 'SwitchField', array(0 => 'Off', 1 => 'On'))->addExtraClass('large-12'), FoundationSwitchField::create('SwitchField2', 'SwitchField', array(0 => 'Off', 1 => 'On'))->addExtraClass('large round'));
     $actions = new FieldList(new FormAction('submitFoundationForm', 'Submit'));
     // set all to required to see the validation message appearance
     $required = array();
     if ($dataFields = $fields->dataFields()) {
         foreach ($dataFields as $child) {
             $required[] = $child->getName();
         }
     }
     $validator = new RequiredFields($required);
     $form = new FoundationForm($this, __FUNCTION__, $fields, $actions, $validator);
     // load submitted data, and clear them from session
     if ($data = Session::get('FoundationForm' . $this->ID)) {
         $form->loadDataFrom($data);
         Session::clear('FoundationForm' . $this->ID);
     }
     return $form;
 }
 public function getFormField()
 {
     $field = FileField::create($this->Name, $this->Title);
     // filter out '' since this would be a regex problem on JS end
     $field->getValidator()->setAllowedExtensions(array_filter(Config::inst()->get('File', 'allowed_extensions')));
     if ($this->getSetting('Folder')) {
         $folder = Folder::get()->byId($this->getSetting('Folder'));
         if ($folder) {
             $field->setFolderName(preg_replace("/^assets\\//", "", $folder->Filename));
         }
     }
     if ($this->Required) {
         // Required validation can conflict so add the Required validation messages
         // as input attributes
         $errorMessage = $this->getErrorMessage()->HTML();
         $field->setAttribute('data-rule-required', 'true');
         $field->setAttribute('data-msg-required', $errorMessage);
     }
     return $field;
 }
 function __construct($controller, $name)
 {
     $f = new FieldList();
     $f->push(BootstrapTextField::create('Name', "Full name"));
     $f->push(BootstrapEmailField::create('Email', "Email (will not be published)"));
     $f->push(BootstrapEmailField::create('ContactNumber', 'Contact number (will not be published)'));
     $f->push(CustomCountryDropdownField::create('Country')->setEmptyString('--please select--'));
     $f->push(BootstrapTextField::create('Town'));
     $f->push(BootstrapTextField::create('Latitude'));
     $f->push(BootstrapTextField::create('Longitude'));
     $f->push(FileField::create('Image'));
     $f->push(BootstrapTextareaField::create('Description')->setRightTitle("<div id='charLeft'><span>200</span></div>"));
     $actions = new FieldList($btn = new FormAction('doSubmit', 'Submit'));
     $btn->addExtraClass("btn");
     $aRequiredFields = array();
     $aRequiredFields[] = "Name";
     $aRequiredFields[] = "Email";
     $aRequiredFields[] = "Description";
     $requiredFields = new RequiredFields();
     parent::__construct($controller, $name, $f, $actions, $requiredFields);
     $this->addExtraClass('form-horizontal ' . get_class());
     //$this->loadValidationScripts($this, $aRequiredFields);
 }
Ejemplo n.º 23
0
 public function __construct()
 {
     parent::__construct('import');
     $this->setMethod('post');
     $this->setEnctype(Form::ENCTYPE_MULTYPART_FORMDATA);
     $commandHidden = new HiddenField('command');
     $this->addElement($commandHidden->setValue('upload-lp'));
     $fileField = new FileField('file');
     $fileField->setLabel(OW::getLanguage()->text('admin', 'lang_file'));
     $this->addElement($fileField);
     $submit = new Submit('submit');
     $this->addElement($submit->setValue(OW::getLanguage()->text('admin', 'clone_form_lbl_submit')));
 }
Ejemplo n.º 24
0
 /**
  * @expectedException \RuntimeException
  * 
  */
 public function testFileFieldGetDataNotWorking()
 {
     $f = new FileField();
     $f->getData();
 }
 function __construct($controller, $name, $fields = null, $actions = null, $validator = null)
 {
     if (!$fields) {
         $helpHtml = _t('TemplateImportForm.Help1');
         $fields = new FieldList(new LiteralField('Help', $helpHtml), $fileField = new FileField('TemplateFile', _t('DynamicTemplateAdmin_TemplateImportForm.FileFieldLabel', 'Template File <small>(Allowed extensions: *.tar.gz, .zip)</small>')));
         $fileField->getValidator()->setAllowedExtensions(array('gz', 'zip'));
     }
     if (!$actions) {
         $actions = new FieldList($importAction = new FormAction('doImport', _t('DynamicTemplateAdmin_TemplateImportForm.BtnImport', 'Import')));
     }
     $importAction->addExtraClass('ss-ui-button');
     if (!$validator) {
         $validator = new RequiredFields('CsvFile');
     }
     parent::__construct($controller, $name, $fields, $actions, $validator);
     $this->addExtraClass('cms');
     $this->addExtraClass('import-form');
 }
Ejemplo n.º 26
0
 public function extraClass()
 {
     if ($this->isDisabled()) {
         $this->addExtraClass('disabled');
     }
     if ($this->isReadonly()) {
         $this->addExtraClass('readonly');
     }
     return parent::extraClass();
 }
Ejemplo n.º 27
0
 /**
  * @author Jeff Ober
  * @param string $label the field's string label
  * @param int $max_size the maximum upload size in bytes
  * @param array $validators a list of callbacks to validate the field data
  * @param array $attributes a list of key/value pairs representing HTML attributes
  **/
 public function __construct($label, $max_size, array $validators = array(), array $attributes = array())
 {
     parent::__construct($label, array('image/png', 'image/gif', 'image/jpg', 'image/jpeg'), $max_size, $validators, $attributes);
 }
Ejemplo n.º 28
0
 public function edit($params)
 {
     if (!isset($params['id']) || !($id = (int) $params['id'])) {
         throw new Redirect404Exception();
         return;
     }
     $language = OW::getLanguage();
     $config = OW::getConfig();
     $sponsor = SPONSORS_BOL_Service::getInstance()->findSponsorById($id);
     if (!$sponsor->id) {
         throw new Redirect404Exception();
         return;
     }
     $sponsorForm = new Form('sponsorForm');
     $sponsorForm->setEnctype('multipart/form-data');
     $element = new TextField('sponsorName');
     $element->setRequired(true);
     $element->setLabel($language->text('sponsors', 'sponsor_name'));
     $element->setInvitation($language->text('sponsors', 'sponsor_name_desc'));
     $element->setValue($sponsor->name);
     $element->setHasInvitation(true);
     $sponsorForm->addElement($element);
     $element = new TextField('sponsorEmail');
     $element->setRequired(true);
     $validator = new EmailValidator();
     $validator->setErrorMessage($language->text('sponsors', 'invalid_email_format'));
     $element->addValidator($validator);
     $element->setLabel($language->text('sponsors', 'sponsor_email'));
     $element->setInvitation($language->text('sponsors', 'sponsor_email_desc'));
     $element->setValue($sponsor->email);
     $element->setHasInvitation(true);
     $sponsorForm->addElement($element);
     $element = new TextField('sponsorWebsite');
     $element->setRequired(true);
     $validator = new UrlValidator();
     $validator->setErrorMessage($language->text('sponsors', 'invalid_url_format'));
     $element->addValidator($validator);
     $element->setLabel($language->text('sponsors', 'sponsor_website'));
     $element->setInvitation($language->text('sponsors', 'sponsor_website_desc'));
     $element->setHasInvitation(true);
     $element->setValue($sponsor->website);
     $sponsorForm->addElement($element);
     $element = new TextField('sponsorAmount');
     $element->setRequired(true);
     $minAmount = $config->getValue('sponsors', 'minimumPayment');
     $validator = new FloatValidator(0);
     $validator->setErrorMessage($language->text('sponsors', 'invalid_amount_value'));
     $element->addValidator($validator);
     $element->setLabel($language->text('sponsors', 'sponsor_payment_amount'));
     $element->setInvitation($language->text('sponsors', 'admin_payment_amount_desc'));
     $element->setHasInvitation(true);
     $element->setValue($sponsor->price);
     $sponsorForm->addElement($element);
     $element = new TextField('sponsorValidity');
     $element->setRequired(true);
     $element->setValue($sponsor->validity);
     $validator = new IntValidator(0);
     $validator->setErrorMessage($language->text('sponsors', 'invalid_numeric_format'));
     $element->addValidator($validator);
     $element->setLabel($language->text('sponsors', 'sponsorship_validatity'));
     $element->setInvitation($language->text('sponsors', 'sponsorship_validatity_desc'));
     $element->setHasInvitation(true);
     $sponsorForm->addElement($element);
     $element = new FileField('sponsorImage');
     $element->setLabel($language->text('sponsors', 'sponsorsh_image_file'));
     $sponsorForm->addElement($element);
     $element = new Submit('editSponsor');
     $element->setValue(OW::getLanguage()->text('sponsors', 'edit_sponsor_btn'));
     $sponsorForm->addElement($element);
     if (OW::getRequest()->isPost()) {
         if ($sponsorForm->isValid($_POST)) {
             $values = $sponsorForm->getValues();
             $allowedImageExtensions = array('jpg', 'jpeg', 'gif', 'png', 'tiff');
             $sponsorImageFile = "";
             if (isset($_FILES['sponsorImage']) && in_array(UTIL_File::getExtension($_FILES['sponsorImage']['name']), $allowedImageExtensions)) {
                 $backupPath = OW::getPluginManager()->getPlugin('sponsors')->getUserFilesDir() . $_FILES['sponsorImage']['name'];
                 move_uploaded_file($_FILES['sponsorImage']['tmp_name'], $backupPath);
                 $sponsorImageFile = $_FILES['sponsorImage']['name'];
             }
             $sponsor->name = $values['sponsorName'];
             $sponsor->email = $values['sponsorEmail'];
             $sponsor->website = $values['sponsorWebsite'];
             $sponsor->price = $values['sponsorAmount'];
             if (!empty($sponsorImageFile)) {
                 $sponsor->image = $sponsorImageFile;
             }
             $sponsor->userId = $sponsor->userId;
             $sponsor->status = $sponsor->status;
             $sponsor->validity = $values['sponsorValidity'];
             if (SPONSORS_BOL_Service::getInstance()->addSponsor($sponsor)) {
                 OW::getFeedback()->info(OW::getLanguage()->text('sponsors', 'sponsor_edit_ok'));
             } else {
                 OW::getFeedback()->error(OW::getLanguage()->text('sponsors', 'sponsor_edit_error'));
             }
         }
     }
     $this->addForm($sponsorForm);
     $fields = array();
     foreach ($sponsorForm->getElements() as $element) {
         if (!$element instanceof HiddenField) {
             $fields[$element->getName()] = $element->getName();
         }
     }
     $this->assign('formData', $fields);
     $this->assign('currentLogoImage', OW::getPluginManager()->getPlugin('sponsors')->getUserFilesUrl() . $sponsor->image);
     $this->setPageHeading(OW::getLanguage()->text('sponsors', 'edit_sponsor_heading'));
     $this->setPageTitle(OW::getLanguage()->text('sponsors', 'edit_sponsor_heading'));
     $this->setPageHeadingIconClass('ow_ic_edit');
 }
 /**
  * Renders the form field, loads requirements. Sets file size based on php.ini
  * Adds the security token
  * 
  * @param array $attributes [description]
  * @return  SSViewer
  */
 public function FieldHolder($attributes = array())
 {
     Requirements::javascript(DROPZONE_DIR . '/javascript/dropzone.js');
     Requirements::javascript(DROPZONE_DIR . '/javascript/file_attachment_field.js');
     if ($this->isCMS()) {
         Requirements::javascript(DROPZONE_DIR . '/javascript/file_attachment_field_backend.js');
     }
     Requirements::css(DROPZONE_DIR . '/css/file_attachment_field.css');
     if (!$this->getSetting('url')) {
         $this->settings['url'] = $this->Link('upload');
     }
     if (!$this->getSetting('maxFilesize')) {
         $this->settings['maxFilesize'] = static::get_filesize_from_ini();
     }
     // The user may not have opted into a multiple upload. If the form field
     // is attached to a record that has a multi relation, set that automatically.
     $this->settings['uploadMultiple'] = $this->IsMultiple();
     // Auto filter images if assigned to an Image relation
     if ($class = $this->getFileClass()) {
         if (Injector::inst()->get($class) instanceof Image) {
             $this->imagesOnly();
         }
     }
     if ($token = $this->getForm()->getSecurityToken()) {
         $this->addParam($token->getName(), $token->getSecurityID());
     }
     return parent::FieldHolder($attributes);
 }
Ejemplo n.º 30
0
 /**
  * @ignore
  *
  * @param array $opts
  *
  * @return FileField
  */
 public static function FileField($opts = [])
 {
     return FileField::createObject($opts);
 }