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; }
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; }
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); }
function MyForm() { $form = Form::create($this, "MyForm", new FieldList(TextField::create("FirstName")->setTitle('First name')->setAttribute("placeholder", "Min. 3 znaky")->setAttribute("data-validation-required-message", "nezabudnite vpísať vaše meno")->setAttribute("required", true), TextField::create("Surname")->setTitle('Last name')->setMaxLength(50)->setAttribute("required", true), EmailField::create("Email")->setTitle("Email address")->setAttribute("required", true)->setAttribute("data-validation-email-message", "nezabudnite napísať existujúci majl")->setAttribute('type', 'email'), DropdownField::create("Cisla")->setTitle("Čísla")->setSource(array("jedna", "dva", "tri"))->addExtraClass("expand")->setEmptyString("musíš vybrať jedno numero"), CheckboxField::create("Donkey")->setTitle("Si donkey?"), CheckboxField::create("Donkey2")->setTitle("Si veľmi dlhý a vráskavý donkey s malými ušami?"), ReadonlyField::create("ReadOnly")->setTitle("Toto nezmeníte.... readonly")->setValue("nemeniteľné"), TextareaField::create("Text")->setTitle("Poznámka"), DateField::create("Dátum")->setConfig("showcalendar", true)->setConfig("jQueryUI.firstDay", 1)->setConfig("jQueryUI.dayNamesMin", array("Ne", "Po", "Ut", "St", "Št", "Pi", "So"))->setLocale('sk_SK'), DatetimeField::create('DátumČas', 'Dátum a čas')->setConfig('datavalueformat', 'yyyy-MM-dd HH:mm')->setConfig('showcalendar', 1), GroupedDropdownField::create("grouped")->setTitle("Zoskupený dropdown")->setSource(array("numbers" => array("1", "2", "3"), "letters" => array("a", "b", "c"))), OptionsetField::create("options")->setTitle("Čísla 2")->setSource(array("jedna", "dva", "tri")), HeaderField::create("header", "Toto je nadpis")->setTitle("overwritten nadpissss"), LiteralField::create("dataless", "html here")->setTitle("dataless")->setContent("<p>Or overwritten here</p><ul><li>item 1</li><li>item 2</li></ul>"), FileField::create("Nahraj")), new FieldList(FormAction::create("doMyForm")->setTitle("Odoslať")->addExtraClass("button radius"), ResetFormAction::create("resetMyForm", "Reset")->addExtraClass("button secondary small radius")), new RequiredFields("Email", "FirstName", "Text"))->setAttribute("novalidate", "novalidate")->addExtraClass("custom horizontal"); return $form; }
public function UploadForm() { return Form::create($this, "UploadForm", FieldList::create(FileField::create("XMLFile", 'Wordpress XML file'), HiddenField::create("BlogHolderID", '', $this->getBlogHolderID())), FieldList::create(FormAction::create('doUpload', 'Import Wordpress XML file'))); }
public function __construct($controller, $name) { parent::__construct($controller, $name, FieldList::create(FileField::create('CsvFile')), FieldList::create(FormAction::create('doUpload', 'Upload')), RequiredFields::create(['CsvFile'])); }
/** * Section for dealing with reply / edit / create threads form * * @return Form Returns the post message form */ function PostMessageForm($addMode = false, $post = false) { $thread = false; if ($post) { $thread = $post->Thread(); } else { if (isset($this->urlParams['ID']) && is_numeric($this->urlParams['ID'])) { $thread = DataObject::get_by_id('ForumThread', $this->urlParams['ID']); } } // Check permissions $messageSet = array('default' => _t('Forum.LOGINTOPOST', 'You\'ll need to login before you can post to that forum. Please do so below.'), 'alreadyLoggedIn' => _t('Forum.LOGINTOPOSTLOGGEDIN', 'I\'m sorry, but you can\'t post to this forum until you\'ve logged in.' . 'If you want to log in as someone else, do so below. If you\'re logged in and you still can\'t post, you don\'t have the correct permissions to post.'), 'logInAgain' => _t('Forum.LOGINTOPOSTAGAIN', 'You have been logged out of the forums. If you would like to log in again to post, enter a username and password below.')); // Creating new thread if ($addMode && !$this->canPost()) { Security::permissionFailure($this, $messageSet); return false; } // Replying to existing thread if (!$addMode && !$post && $thread && !$thread->canPost()) { Security::permissionFailure($this, $messageSet); return false; } // Editing existing post if (!$addMode && $post && !$post->canEdit()) { Security::permissionFailure($this, $messageSet); return false; } $forumBBCodeHint = $this->renderWith('Forum_BBCodeHint'); $fields = new FieldList($post && $post->isFirstPost() || !$thread ? new TextField("Title", _t('Forum.FORUMTHREADTITLE', 'Title')) : new ReadonlyField('Title', _t('Forum.FORUMTHREADTITLE', ''), 'Re:' . $thread->Title), new TextareaField("Content", _t('Forum.FORUMREPLYCONTENT', 'Content')), new LiteralField("BBCodeHelper", "<div class=\"BBCodeHint\">[ <a href=\"#BBTagsHolder\" id=\"BBCodeHint\">" . _t('Forum.BBCODEHINT', 'View Formatting Help') . "</a> ]</div>" . $forumBBCodeHint), new CheckboxField("TopicSubscription", _t('Forum.SUBSCRIBETOPIC', 'Subscribe to this topic (Receive email notifications when a new reply is added)'), $thread ? $thread->getHasSubscribed() : false)); if ($thread) { $fields->push(new HiddenField('ThreadID', 'ThreadID', $thread->ID)); } if ($post) { $fields->push(new HiddenField('ID', 'ID', $post->ID)); } // Check if we can attach files to this forum's posts if ($this->canAttach()) { $fields->push(FileField::create("Attachment", _t('Forum.ATTACH', 'Attach file'))); } // If this is an existing post check for current attachments and generate // a list of the uploaded attachments if ($post && ($attachmentList = $post->Attachments())) { if ($attachmentList->exists()) { $attachments = "<div id=\"CurrentAttachments\"><h4>" . _t('Forum.CURRENTATTACHMENTS', 'Current Attachments') . "</h4><ul>"; $link = $this->Link(); // An instance of the security token $token = SecurityToken::inst(); foreach ($attachmentList as $attachment) { // Generate a link properly, since it requires a security token $attachmentLink = Controller::join_links($link, 'deleteattachment', $attachment->ID); $attachmentLink = $token->addToUrl($attachmentLink); $attachments .= "<li class='attachment-{$attachment->ID}'>{$attachment->Name} [<a href='{$attachmentLink}' rel='{$attachment->ID}' class='deleteAttachment'>" . _t('Forum.REMOVE', 'remove') . "</a>]</li>"; } $attachments .= "</ul></div>"; $fields->push(new LiteralField('CurrentAttachments', $attachments)); } } $actions = new FieldList(new FormAction("doPostMessageForm", _t('Forum.REPLYFORMPOST', 'Post'))); $required = $addMode === true ? new RequiredFields("Title", "Content") : new RequiredFields("Content"); $form = new Form($this, 'PostMessageForm', $fields, $actions, $required); $this->extend('updatePostMessageForm', $form, $post); if ($post) { $form->loadDataFrom($post); } return $form; }