/**
  * @return Comosite FieldSet with Categorys and Items
  */
 function getCompositeField()
 {
     //create new composite field group for each category
     $oCatFieldSet = new CompositeField();
     // Set the field group ID
     $oCatFieldSet->setID('Cat' . $this->ID);
     $oCatFieldSet->addExtraClass('category');
     //create new composite field group for each category
     $oCatField = new TextField($this->ID . '_' . $this->FieldName, $this->Title, null, null);
     $oCatField->addExtraClass('category-field');
     //Add Category Percentage Field to the Form
     $oCatFieldSet->push($oCatField);
     if ($this->Description) {
         $oCatDescField = new LiteralField($this->ID . '_Description', '<p class="category-field-desc">' . $this->Description . '</p>');
         $oCatDescField->addExtraClass('category-field');
         $oCatFieldSet->push($oCatDescField);
     }
     //Add item Composite Field to this Composite Field
     //now get all of the items matched with this category
     $oFormCategoryItems = self::FormCategoryItems();
     foreach ($oFormCategoryItems as $item) {
         $oCatFieldSet->push($item->getFormField());
     }
     return $oCatFieldSet;
 }
 public function getColumnContent($gridField, $record, $columnName)
 {
     if (!$record->canEdit()) {
         return;
     }
     $field = new CompositeField();
     if (!$record instanceof ElementVirtualLinked) {
         $field->push(GridField_FormAction::create($gridField, 'UnlinkRelation' . $record->ID, false, "unlinkrelation", array('RecordID' => $record->ID))->addExtraClass('gridfield-button-unlink')->setAttribute('title', _t('GridAction.UnlinkRelation', "Unlink"))->setAttribute('data-icon', 'chain--minus'));
     }
     if ($record->canDelete() && $record->VirtualClones()->count() == 0) {
         $field->push(GridField_FormAction::create($gridField, 'DeleteRecord' . $record->ID, false, "deleterecord", array('RecordID' => $record->ID))->addExtraClass('gridfield-button-delete')->setAttribute('title', _t('GridAction.Delete', "Delete"))->setAttribute('data-icon', 'cross-circle')->setDescription(_t('GridAction.DELETE_DESCRIPTION', 'Delete')));
     }
     return $field->Field();
 }
 public function push(FormField $field)
 {
     parent::push($field);
     if ($field instanceof ComponentFieldHolder_Item) {
         $field->setHolder($this);
     }
 }
    /**                                                              
     * Constructor                                                   
     *                                                               
     * @param  object $controller The controller class                           
     * @param  string $name       The name of the form class              
     * @return object The form                                       
     */
    function __construct($controller, $name)
    {
        //FILTER BLOCK 1 : WHERE ARE YOU
        // Create new group
        $oFilterField1 = new CompositeField();
        // Set the field group ID
        $oFilterField1->setID('Group1');
        // Add fields to the group
        $oFilterField1->push(new LiteralField('Group1Title', '<div class="filter-title-block">Where are you?</div>'));
        $oFilterField1->push(new DropdownField('Country', '', Geoip::getCountryDropDown(), 'NZ'));
        //FILTER BLOCK 2: UPLOAD IMAGE
        // Create new group
        $oFilterField2 = new CompositeField();
        // Set the field group ID
        $oFilterField2->setID('Group2');
        // Add fields to the group
        $oFilterField2->push(new LiteralField('Group2Title', '<div class="filter-title-block">When can you help?</div>'));
        //Set Date Defaults
        $tToday = mktime(0, 0, 0, date("m"), date("d"), date("Y"));
        $dToday = date("d/m/Y", $tToday);
        $tNextMonth = mktime(0, 0, 0, date("m") + 2, date("d"), date("Y"));
        $dNextMonth = date("d/m/Y", $tNextMonth);
        //Check if Dates are Set otherwise use Defaults
        $sFromDate = $this->sFromDate != '' ? $this->sFromDate : $dToday;
        $sToDate = $this->sToDate != '' ? $this->sToDate : $dNextMonth;
        //Date Fields
        $oFromDate = new DatePickerField('FromDate', 'From', $sFromDate);
        $oToDate = new DatePickerField('ToDate', 'To', $sToDate);
        $oFilterField2->push($oFromDate);
        $oFilterField2->push($oToDate);
        DatePickerField::$showclear = false;
        // Create new fieldset
        $oFields = new FieldSet();
        // Add the groups to the fieldset
        $oFields->push($oFilterField1);
        $oFields->push($oFilterField2);
        // Create the form action
        $oAction = new FieldSet(new FormAction('SubmitFilter', 'Find events'));
        // Add custom jQuery validation script for requred fields
        Requirements::customScript('
			
		');
        // Construct the form
        parent::__construct($controller, $name, $oFields, $oAction);
    }
 /**
  * Presents a form to select a language to translate the pages selected with batch actions into.
  *
  * @param string $pageIDs | null
  * @return Form $form
  */
 public function TranslatePagesForm($pageIDs = null)
 {
     Versioned::reading_stage('Stage');
     // Needs this for changes to effect draft tree
     $languages = Translatable::get_allowed_locales();
     $action = FormAction::create('doTranslatePages', 'Translate')->setUseButtonTag('true')->addExtraClass('ss-ui-button ss-ui-action-constructive batch-form-actions')->setUseButtonTag(true);
     $actions = FieldList::create($action);
     $allFields = new CompositeField();
     $allFields->addExtraClass('batch-form-body');
     if ($pageIDs == null) {
         $pageIDs = $this->getRequest()->getVar('PageIDs');
     } else {
         $allFields->push(new LiteralField("ErrorParent", '<p class="message bad">Invalid parent selected, please choose another</p>'));
     }
     $allFields->push(new HiddenField("PageIDs", "PageIDs", $pageIDs));
     $allFields->push(LanguageDropdownField::create("NewTransLang", _t('Translatable.NEWLANGUAGE', 'New language'), $languages));
     $headings = new CompositeField(new LiteralField('Heading', sprintf('<h3 class="">%s</h3>', _t('HtmlEditorField.MOVE', 'Choose Language...'))));
     $headings->addExtraClass('cms-content-header batch-pages');
     $fields = new FieldList($headings, $allFields);
     $form = Form::create($this, 'TranslatePagesForm', $fields, $actions);
     return $form;
 }
 /**
  * @param Controller $controller
  * @param String $name
  * @param Order $order
  * @param String
  */
 function __construct(Controller $controller, $name, Order $order, $returnToLink = '')
 {
     $fields = new FieldList(new HiddenField('OrderID', '', $order->ID));
     if ($returnToLink) {
         $fields->push(new HiddenField("returntolink", "", convert::raw2att($returnToLink)));
     }
     $bottomFields = new CompositeField();
     $bottomFields->addExtraClass('bottomOrder');
     if ($order->Total() > 0) {
         $paymentFields = EcommercePayment::combined_form_fields($order->getTotalAsMoney()->NiceLongSymbol(false), $order);
         foreach ($paymentFields as $paymentField) {
             $bottomFields->push($paymentField);
         }
         if ($paymentRequiredFields = EcommercePayment::combined_form_requirements($order)) {
             $requiredFields = array_merge($requiredFields, $paymentRequiredFields);
         }
     } else {
         $bottomFields->push(new HiddenField("PaymentMethod", "", ""));
     }
     $fields->push($bottomFields);
     $actions = new FieldList(new FormAction('dopayment', _t('OrderForm.PAYORDER', 'Pay balance')));
     $requiredFields = array();
     $validator = OrderForm_Payment_Validator::create($requiredFields);
     $form = parent::__construct($controller, $name, $fields, $actions, $validator);
     //extension point
     $this->extend('updateFields', $fields);
     $this->setFields($fields);
     $this->extend('updateActions', $actions);
     $this->setActions($actions);
     $this->extend('updateValidator', $validator);
     $this->setValidator($validator);
     $this->setFormAction($controller->Link($name));
     $oldData = Session::get("FormInfo.{$this->FormName()}.data");
     if ($oldData && (is_array($oldData) || is_object($oldData))) {
         $this->loadDataFrom($oldData);
     }
     $this->extend('updateOrderForm_Payment', $this);
 }
 public function testPushAndUnshift()
 {
     $composite = new CompositeField(new TextField('Middle'));
     $composite->push(new TextField('End'));
     /* There are now 2 fields in the set */
     $this->assertEquals(2, $composite->getChildren()->Count());
     /* The most recently added field is at the end of the set */
     $this->assertEquals('End', $composite->getChildren()->Last()->getName());
     $composite->unshift(new TextField('Beginning'));
     /* There are now 3 fields in the set */
     $this->assertEquals(3, $composite->getChildren()->Count());
     /* The most recently added field is at the beginning of the set */
     $this->assertEquals('Beginning', $composite->getChildren()->First()->getName());
 }
 /**
  * Return a {@link Form} instance with a
  * a {@link TableListField} for the current
  * {@link LinkCheckRun} record that we're currently
  * looking it, the ID for that LinkCheckRun record
  * is accessible from the URL as the "ID" parameter.
  * 
  * @uses LinkCheckAdmin->getLinkCheckRun()
  * @todo Fix up the hardcoded english strings
  * @todo Split functionality to separate methods
  * 
  * @return Form
  */
 public function getEditForm($id = null)
 {
     $run = $this->getLinkCheckRun($id);
     if (!$run) {
         return false;
     }
     $runCMSFields = $run->getCMSFields();
     $runCompFields = new CompositeField();
     $runCompFields->setID('RunFields');
     if ($runCMSFields) {
         foreach ($runCMSFields as $runCMSField) {
             $runCompFields->push($runCMSField);
         }
     }
     $brokenLinkCount = $run->BrokenLinks() ? $run->BrokenLinks()->Count() : 0;
     $finishedDate = $run->obj('FinishDate')->Nice();
     $pagesChecked = $run->PagesChecked;
     if ($run->IsComplete) {
         // Run is complete
         if ($brokenLinkCount == 1) {
             $resultNumField = new LiteralField('ResultNo', "<p>Finished at {$finishedDate}. {$pagesChecked} pages were checked. 1 broken link was found.</p>");
         } elseif ($brokenLinkCount > 0) {
             $resultNumField = new LiteralField('ResultNo', "<p>Finished at {$finishedDate}. {$pagesChecked} pages were checked. {$brokenLinkCount} broken links were found.</p>");
         } else {
             $resultNumField = new LiteralField('ResultNo', "<p>Finished at {$finishedDate}. {$pagesChecked} pages were checked. No broken links were found.</p>");
         }
     } else {
         // Run not completed yet
         if ($brokenLinkCount == 1) {
             $resultNumField = new LiteralField('ResultNo', '<p>This link check run is not completed yet. 1 broken link found so far.</p>');
         } elseif ($brokenLinkCount > 0) {
             $resultNumField = new LiteralField('ResultNo', "<p>This link check run is not completed yet. {$brokenLinkCount} broken links found so far.</p>");
         } else {
             $resultNumField = new LiteralField('ResultNo', '<p>This link check run is not completed yet. No broken links found so far.</p>');
         }
     }
     $runDate = $run->obj('Created')->Nice();
     $fields = new FieldSet(new TabSet('Root', new Tab(_t('LinkCheckAdmin.CHECKRUN', 'Results'), new HeaderField('Link check run', 2), new LiteralField('ResultText', "<p>Run at {$runDate}</p>"), $resultNumField, $runCompFields)));
     $fields->push(new HiddenField('LinkCheckRunID', '', $run->ID));
     $fields->push(new HiddenField('ID', '', $run->ID));
     $actions = new FieldSet(new FormAction('save', 'Save'));
     $form = new Form($this, 'EditForm', $fields, $actions);
     $form->loadDataFrom($run);
     return $form;
 }
 /**
  * Puts together the fields for the Order Form (and other front-end purposes).
  * @return Fieldset
  **/
 public function getFields($member = null)
 {
     $fields = parent::getEcommerceFields();
     if (EcommerceConfig::get("OrderAddress", "use_separate_shipping_address")) {
         $shippingFieldsHeader = new CompositeField(new HeaderField('SendGoodsToADifferentAddress', _t('OrderAddress.SENDGOODSTODIFFERENTADDRESS', 'Send goods to different address'), 3), new LiteralField('ShippingNote', '<p class="message warning">' . _t('OrderAddress.SHIPPINGNOTE', 'Your goods will be sent to the address below.') . '</p>'), new LiteralField('ShippingHelp', '<p>' . _t('OrderAddress.SHIPPINGHELP', 'You can use this for gift giving. No billing information will be disclosed to this address.') . '</p>'));
         if ($member) {
             if ($member->exists()) {
                 $addresses = $this->previousAddressesFromMember($member);
                 if ($addresses) {
                     if ($addresses->count() > 1) {
                         $shippingFieldsHeader->push(new SelectOrderAddressField('SelectShippingAddressField', _t('OrderAddress.SELECTBILLINGADDRESS', 'Select Shipping Address'), $addresses));
                     }
                 }
             }
             $shippingFields = new CompositeField(new TextField('ShippingFirstName', _t('OrderAddress.FIRSTNAME', 'First Name')), new TextField('ShippingSurname', _t('OrderAddress.SURNAME', 'Surname')));
         } else {
             $shippingFields = new CompositeField(new TextField('ShippingFirstName', _t('OrderAddress.FIRSTNAME', 'First Name')), new TextField('ShippingSurname', _t('OrderAddress.SURNAME', 'Surname')));
         }
         $shippingFields->push(new TextField('ShippingPrefix', _t('OrderAddress.PREFIX', 'Title (e.g. Ms)')));
         $shippingFields->push(new TextField('ShippingAddress', _t('OrderAddress.ADDRESS', 'Address')));
         $shippingFields->push(new TextField('ShippingAddress2', _t('OrderAddress.ADDRESS2', '&nbsp;')));
         $shippingFields->push(new TextField('ShippingCity', _t('OrderAddress.CITY', 'Town')));
         $shippingFields->push($this->getPostalCodeField("ShippingPostalCode"));
         $shippingFields->push($this->getRegionField("ShippingRegionID"));
         $shippingFields->push($this->getCountryField("ShippingCountry"));
         $shippingFields->push(new TextField('ShippingPhone', _t('OrderAddress.PHONE', 'Phone')));
         $shippingFields->push(new TextField('ShippingMobilePhone', _t('OrderAddress.MOBILEPHONE', 'Mobile Phone')));
         $this->makeSelectedFieldsReadOnly($shippingFields);
         $shippingFieldsHeader->SetID("ShippingFieldsHeader");
         $shippingFields->addExtraClass("orderAddressHolder");
         $fields->push($shippingFieldsHeader);
         $shippingFields->SetID('ShippingFields');
         $fields->push($shippingFields);
     }
     $this->extend('augmentEcommerceShippingAddressFields', $fields);
     return $fields;
 }
 public function scrub($request)
 {
     if (!Director::is_cli()) {
         $renderer = DebugView::create();
         $renderer->writeHeader();
         $renderer->writeInfo("Environment Builder", Director::absoluteBaseURL());
         echo "<div class=\"scrub\">";
     }
     $cruft = array();
     $tableList = DB::getConn()->tableList();
     $dataClasses = ClassInfo::subclassesFor('DataObject');
     array_shift($dataClasses);
     foreach ($tableList as $table) {
         if (!in_array($table, $dataClasses)) {
             $cruftTables[$table] = array("DataClass" => $table, "WholeTable" => true);
         }
     }
     foreach ($dataClasses as $dataClass) {
         if (class_exists($dataClass)) {
             $SNG = singleton($dataClass);
             if (!$SNG instanceof TestOnly) {
                 $classCruft = $SNG->Cruft();
                 if (!empty($classCruft)) {
                     $cruft[] = $classCruft;
                 }
                 foreach ($SNG->many_many() as $relationship => $childClass) {
                     unset($cruftTables["{$dataClass}_{$relationship}"]);
                 }
             }
             if ($SNG->hasExtension("Versioned")) {
                 unset($cruftTables["{$dataClass}_versions"]);
                 unset($cruftTables["{$dataClass}_Live"]);
                 unset($cruftTables["{$dataClass}_Stage"]);
             }
         }
     }
     $cruft = array_merge(array_values($cruftTables), $cruft);
     $form = $this->FormDeleteCruft();
     $form->setFormAction("/DatabaseAdmin/FormDeleteCruft");
     $fields = $form->Fields();
     foreach ($cruft as $classCruft) {
         $group = new CompositeField(array(new HeaderField($classCruft["DataClass"])));
         if (!empty($classCruft["WholeTable"]) && $classCruft["WholeTable"]) {
             $group->push(new CompositeField(array(new CheckboxField("DeleteSpec[{$classCruft["DataClass"]}][WholeTable]", "Whole {$classCruft["DataClass"]} Table"))));
         }
         if (!empty($classCruft["Fields"])) {
             $fieldsGroup = new CompositeField(array(new HeaderField("DeleteSpec[{$classCruft["DataClass"]}][Fields]", "Fields", 3)));
             foreach ($classCruft["Fields"] as $fieldName => $field) {
                 $fieldsGroup->push(new CheckboxField("DeleteSpec[{$classCruft["DataClass"]}][Fields][{$fieldName}]", "{$fieldName} ({$field["Type"]})"));
             }
             $group->push($fieldsGroup);
         }
         if (!empty($classCruft["Indexes"])) {
             $indexesGroup = new CompositeField(array(new HeaderField("DeleteSpec[{$classCruft["DataClass"]}][Indexes]", "Indexes", 3)));
             foreach ($classCruft["Indexes"] as $indexName => $index) {
                 $indexesGroup->push(new CheckboxField("DeleteSpec[{$classCruft["DataClass"]}][Indexes][{$indexName}]", "{$indexName} ({$index["Column_name"]})"));
             }
             $group->push($indexesGroup);
         }
         if (!empty($classCruft["ManyManyFields"]) || !empty($classCruft["ManyManyIndexes"])) {
             $relationships = array_unique(array_merge(array_keys(isset($classCruft["ManyManyFields"]) ? $classCruft["ManyManyFields"] : array()), array_keys(isset($classCruft["ManyManyIndexes"]) ? $classCruft["ManyManyIndexes"] : array())));
             foreach ($relationships as $relationship) {
                 $manyManyGroup = new CompositeField(array(new HeaderField("DeleteSpec[{$classCruft["DataClass"]}][ManyMany][{$relationship}]", "Many-Many: {$relationship}", 4)));
                 if (!empty($classCruft["ManyManyFields"][$relationship])) {
                     $manyManyGroup->push($fieldsGroup = new CompositeField(array(new HeaderField("DeleteSpec[{$classCruft["DataClass"]}][ManyMany][{$relationship}][Fields]", "Fields", 5))));
                     foreach ($classCruft["ManyManyFields"][$relationship] as $fieldName => $field) {
                         $fieldsGroup->push(new CheckboxField("DeleteSpec[{$classCruft["DataClass"]}][ManyMany][{$relationship}][Fields][{$fieldName}]", "{$fieldName} ({$field["Type"]})"));
                     }
                 }
                 if (!empty($classCruft["ManyManyIndexes"][$relationship])) {
                     $manyManyGroup->push($fieldsGroup = new CompositeField(array(new HeaderField("DeleteSpec[{$classCruft["DataClass"]}][ManyMany][{$relationship}][Indexes]", "Indexes", 5))));
                     foreach ($classCruft["ManyManyIndexes"][$relationship] as $indexName => $index) {
                         $fieldsGroup->push(new CheckboxField("DeleteSpec[{$classCruft["DataClass"]}][ManyMany][{$relationship}][Indexes][{$indexName}]", "{$indexName} ({$index["Column_name"]})"));
                     }
                 }
                 $group->push($manyManyGroup);
             }
         }
         $fields->push($group);
     }
     echo $this->owner->renderWith(array("DatabaseAdminCleaner", "ContentController"), array("FormDeleteCruft" => $form));
     if (!Director::is_cli()) {
         echo "</div>";
         $renderer->writeFooter();
     }
 }
 /**
  * Add pament fields for the current payment method. Also adds payment method as a required field.
  * 
  * @param Array $fields Array of fields
  * @param OrderFormValidator $validator Checkout form validator
  * @param Order $order The current order
  */
 private function addPaymentFields(&$fields, &$validator, $order)
 {
     $paymentFields = new CompositeField();
     foreach (Payment::combined_form_fields($order->Total->getAmount()) as $field) {
         //Bit of a nasty hack to customize validation error message
         if ($field->Name() == 'PaymentMethod') {
             $field->setCustomValidationMessage(_t('CheckoutPage.SELECT_PAYMENT_METHOD', "Please select a payment method."));
         }
         $paymentFields->push($field);
     }
     $paymentFields->setID('PaymentFields');
     $fields['Payment'][] = $paymentFields;
     //TODO need to check required payment fields
     //$requiredPaymentFields = Payment::combined_form_requirements();
     $validator->addRequiredField('PaymentMethod');
 }
    /**                                                              
     * Constructor                                                   
     *                                                               
     * @param  object $controller The controller class                           
     * @param  string $name       The name of the form class              
     * @return object The form                                       
     */
    function __construct($controller, $name)
    {
        //DATA STEP 1 : BASIC INFO
        // Create new group
        $oDataField1 = new CompositeField();
        // Set the field group ID
        $oDataField1->setID('Group1');
        // Add fields to the group
        $oDataField1->push(new LiteralField('Group1Title', '<div class="data-title-block"><img src="themes/lyc2012/img/s1.jpg" />
		<h2>Overview</h2><span>Basic event results. If you do not know the exact numbers, simply make an estimate.</span></div>'));
        $oDataField1->push(new DropdownField('CleanUpGroupID', 'Select an Event to add data for', self::mapCleanUps()));
        $oDataField1->push(new TextField('Participants', 'Number of participants'));
        $oDataField1->push(new LiteralField('Help1', '<p class="category-field-desc">How many people turned-up to help? Your number will be added to the tally at the top of this page.</p>'));
        $oDataField1->push(new TextField('Sacks', 'Sacks of rubbish'));
        $oDataField1->push(new LiteralField('Help2', '<p class="category-field-desc">How many full rubbish sacks did you collect? Your number will be added to the tally at the top of this page.</p>'));
        $oDataField1->push(new TextField('Distance', 'Distance covered'));
        $oDataField1->push(new LiteralField('Help3', '<p class="category-field-desc">How far did participants walk while cleaning-up? This provides an idea of the state of your coastlines.</p>'));
        $oDataField1->push(new TextField('Time', 'Time spent'));
        $oDataField1->push(new LiteralField('Help3', '<p class="category-field-desc">How long did participants spend cleaning-up? This provides an idea of the effort involved.</p>'));
        $oDataField1->push(new LiteralField('Group1Anchor', '
		<div class="Actions margin-top">
			<p class="continue">Got a photo or rubbish data? If yes, continue below. Otherwise</p><a class="orange action" href="#end">Finish now</a>
		</div>'));
        //DATA STEP 2 : UPLOAD IMAGE
        // Create new group
        $oDataField2 = new CompositeField();
        // Set the field group ID
        $oDataField2->setID('Group2');
        //Set-up uploadify Field
        $oDataField2->push(new LiteralField('Group2Title', '<div class="data-title-block"><img src="themes/lyc2012/img/s2.jpg" />
		<h2>Photo</h2><span>(optional) If you do not have any photos from your event, skip this step. </span></div>'));
        $oDataField2->push(new SimpleImageField('DataImageFile', 'Upload event photo'));
        $oDataField2->push(new LiteralField('Help3', '<p class="category-field-desc">Any event photo, but the preference is for a photo of the rubbish collected or of your event participants. Max file size 100KB.</p>'));
        $oDataField2->push(new LiteralField('Group1Anchor', '
		<div class="Actions margin-top">
			<p class="continue">Got rubbish data? If yes, continue below. Otherwise</p><a class="orange action" href="#end">Finish now</a>
		</div>'));
        //DATA STEP 3 : DATA FIELDS
        // Create new group
        $oFieldsCat = new CompositeField();
        $oFieldsCat->setID('Group3');
        $oFieldsCat->push(new LiteralField('Group3Title', '<div class="data-title-block"><img src="themes/lyc2012/img/s3.jpg" />
		<h2>Results</h2><span>(optional) Complete this section if you have estimated or counted the types of rubbish collected.</span></div>'));
        $oFieldsCat->push(new LiteralField('Group3Title2', '<div class="data-title-block"><img src="themes/lyc2012/img/either.png" />
		<h2>Upload</h2><span>Choose this option if you have filled-in your data electronically on our Event Results Spreadsheet.</span></div>'));
        $oFieldsCat->push(new FileField('DataSheetFile', 'Upload a spreadsheet containing your data'));
        //$oFieldsCat->push(new LiteralField('Help3', '<p class="category-field-desc">Choose this option if you have filled-in your data electronically on our Event Results Spreadsheet.</p>'));
        $oFieldsCat->push(new LiteralField('Group1Anchor', '
		<div class="Actions margin-top">
			<p class="continue">Skip this step and enter data below. Otherwise</p><a class="action orange" href="#end">Finish now</a>
		</div>'));
        $oFieldsCat->push(new LiteralField('Group3Title2', '<div class="data-title-block"><img src="themes/lyc2012/img/OR.png" />
		<h2>Enter</h2><span>Choose this option if you have recorded data but do not have it in our spreadsheet (e.g. you recorded it on paper).</span></div>'));
        //Get all FormCategorys
        $oFormCategorys = DataObject::get('FormCategory');
        if ($oFormCategorys) {
            foreach ($oFormCategorys as $category) {
                $oFieldsCat->push($category->getCompositeField());
            }
        }
        $oFieldsCat->push(new LiteralField('Group4Anchor', '
		<a name="end">&nbsp;</a>
		'));
        // Create new fieldset
        $oFields = new FieldSet();
        // Add the groups to the fieldset
        $oFields->push($oDataField1);
        $oFields->push($oDataField2);
        $oFields->push($oFieldsCat);
        //$oFields->push($oDataField4);
        // Create the form action
        $oAction = new FieldSet(new FormAction('SubmitDataSheet', 'Share Results'));
        // Add custom jQuery validation script for requred fields
        Requirements::javascript("mysite/javascript/DataFormVal.js");
        // Construct the form
        parent::__construct($controller, $name, $oFields, $oAction);
    }
Exemplo n.º 13
0
 /**
  * Pushes the given field to the group
  *
  * @param FormField $field       Field to push
  * @param bool      $breakBefore Insert a line break before the field?
  * @param bool      $breakAfter  Insert a line break after the field?
  * 
  * @return void
  * 
  * @author Sebastian Diel <*****@*****.**>
  * @since 06.06.2012
  */
 public function push(FormField $field, $breakBefore = false, $breakAfter = false)
 {
     $field->BreakAfter = $breakAfter;
     $field->BreakBefore = $breakBefore;
     parent::push($field);
     $fields = $this->getFields();
     if (!is_null($fields)) {
         $fields->removeByName($field->getName());
     }
 }
 /**
  * @param Member $member
  * @return FieldList
  **/
 public function getFields(Member $member = null)
 {
     $fields = parent::getEcommerceFields();
     $fields->push(new HeaderField('BillingDetails', _t('OrderAddress.BILLINGDETAILS', 'Billing Address'), 3));
     $fields->push(new TextField('Phone', _t('OrderAddress.PHONE', 'Phone')));
     $billingFields = new CompositeField();
     $hasPreviousAddresses = false;
     if ($member) {
         if ($member->exists() && !$member->IsShopAdmin()) {
             $this->FillWithLastAddressFromMember($member, true);
             $addresses = $member->previousOrderAddresses($this->baseClassLinkingToOrder(), $this->ID, $onlyLastRecord = false, $keepDoubles = false);
             //we want MORE than one here not just one.
             if ($addresses->count() > 1) {
                 $fields->push(SelectOrderAddressField::create('SelectBillingAddressField', _t('OrderAddress.SELECTBILLINGADDRESS', 'Select Billing Address'), $addresses));
                 $hasPreviousAddresses = true;
             }
         }
     }
     //$billingFields->push(new TextField('MobilePhone', _t('OrderAddress.MOBILEPHONE','Mobile Phone')));
     $mappingArray = $this->Config()->get("fields_to_google_geocode_conversion");
     if (is_array($mappingArray) && count($mappingArray)) {
         if (!class_exists("GoogleAddressField")) {
             user_error("You must install the Sunny Side Up google_address_field module OR remove entries from: BillingAddress.fields_to_google_geocode_conversion");
         }
         $billingFields->push($billingEcommerceGeocodingField = new GoogleAddressField('BillingEcommerceGeocodingField', _t('OrderAddress.FIND_ADDRESS', 'Find address'), Session::get("BillingEcommerceGeocodingFieldValue")));
         $billingEcommerceGeocodingField->setFieldMap($mappingArray);
         //$billingFields->push(new HiddenField('Address2', "NOT SET", "NOT SET"));
         //$billingFields->push(new HiddenField('City', "NOT SET", "NOT SET"));
     }
     //$billingFields->push(new TextField('Prefix', _t('OrderAddress.PREFIX','Title (e.g. Ms)')));
     $billingFields->push(new TextField('Address', _t('OrderAddress.ADDRESS', 'Address')));
     $billingFields->push(new TextField('Address2', _t('OrderAddress.ADDRESS2', '')));
     $billingFields->push(new TextField('City', _t('OrderAddress.CITY', 'Town')));
     $billingFields->push($this->getPostalCodeField("PostalCode"));
     $billingFields->push($this->getRegionField("RegionID", "RegionCode"));
     $billingFields->push($this->getCountryField("Country"));
     $billingFields->addExtraClass('billingFields');
     $billingFields->addExtraClass("orderAddressHolder");
     $this->makeSelectedFieldsReadOnly($billingFields->FieldList());
     $fields->push($billingFields);
     $this->extend('augmentEcommerceBillingAddressFields', $fields);
     return $fields;
 }
 /**
  * get CMS fields describing the member in the CMS when viewing the order.
  *
  * @return CompositeField
  **/
 public function getEcommerceFieldsForCMS()
 {
     $fields = new CompositeField();
     $memberTitle = new ReadonlyField("MemberTitle", _t("Member.TITLE", "Name"), "<p>" . _t("Member.TITLE", "Name") . ": " . $this->owner->getTitle() . "</p>");
     $memberTitle->dontEscape = true;
     $fields->push($memberTitle);
     $memberEmail = new ReadonlyField("MemberEmail", _t("Member.EMAIL", "Email"), "<p>" . _t("Member.EMAIL", "Email") . ": " . $this->owner->Email . "</p>");
     $memberEmail->dontEscape = true;
     $fields->push($memberEmail);
     $lastLogin = new ReadonlyField("MemberLastLogin", _t("Member.LASTLOGIN", "Last Login"), "<p>" . _t("Member.LASTLOGIN", "Last Login") . ": " . $this->owner->dbObject('LastVisited')->Nice() . "</p>");
     $lastLogin->dontEscape = true;
     $fields->push($lastLogin);
     $group = EcommerceRole::get_customer_group();
     if (!$group) {
         $group = new Group();
     }
     $linkField = new LiteralField("MemberLinkField", "\n\t\t\t<h3>" . _t("Member.EDIT_CUSTOMER", "Edit Customer") . "</h3>\n\t\t\t<ul>\n\t\t\t\t<li><a href=\"/admin/security/EditForm/field/Members/item/" . $this->owner->ID . "/edit\"  data-popup=\"true\">" . _t("Member.EDIT", "Edit") . " <i>" . $this->owner->getTitle() . "</i></a></li>\n\t\t\t\t<li><a href=\"/admin/security/show/" . $group->ID . "/\"  data-popup=\"true\">" . _t("Member.EDIT_ALL_CUSTOMERS", "Edit All Customers") . "</a></li>\n\t\t\t</ul>\n\t\t\t");
     $fields->push($linkField);
     return $fields;
 }
Exemplo n.º 16
0
 /**
  * Add a new child field to the end of the set.
  */
 public function push($field)
 {
     parent::push($field);
     $field->setTabSet($this);
 }
    function Form()
    {
        if ($this->URLParams['Action'] == 'complete') {
            return;
        }
        $dataFields = singleton('Member')->getCMSFields()->dataFields();
        if ($this->CustomisedLables) {
            $customisedLables = Convert::json2array($this->CustomisedLables);
        }
        $fields = array();
        if ($this->Fields) {
            $fields = explode(",", $this->Fields);
        }
        $memberInfoSection = new CompositeField();
        if (!empty($fields)) {
            foreach ($fields as $field) {
                if (isset($dataFields[$field]) && $dataFields[$field]) {
                    if (isset($customisedLables[$field])) {
                        $dataFields[$field]->setTitle($customisedLables[$field]);
                    }
                    if (is_a($dataFields[$field], "ImageField")) {
                        $dataFields[$field] = new SimpleImageField($dataFields[$field]->Name(), $dataFields[$field]->Title());
                    }
                    $memberInfoSection->push($dataFields[$field]);
                }
            }
        }
        $formFields = new FieldSet(new HeaderField("MemberInfo", _t("SubscriptionPage.Information", "Member Infomation:"), 2), $memberInfoSection);
        $memberInfoSection->setID("MemberInfoSection");
        if ($this->NewsletterTypes) {
            $newsletters = DataObject::get("NewsletterType", "ID IN (" . $this->NewsletterTypes . ")");
        }
        if (isset($newsletters) && $newsletters && $newsletters->count() > 1) {
            $newsletterSection = new CompositeField(new LabelField("Newsletters", _t("SubscriptionPage.To", "Subscribe to:"), 4), new CheckboxSetField("NewsletterSelection", "", $newsletters));
            $formFields->push($newsletterSection);
        }
        $buttonTitle = $this->SubmissionButtonText;
        $actions = new FieldSet(new FormAction('doSubscribe', $buttonTitle));
        $form = new Form($this, "Form", $formFields, $actions);
        // using jQuery to customise the validation of the form
        $FormName = $form->FormName();
        $messages = $this->CustomisedErrors;
        if ($this->Required) {
            $jsonRuleArray = array();
            foreach (Convert::json2array($this->Required) as $field => $true) {
                if ($true) {
                    if ($field === 'Email') {
                        $jsonRuleArray[] = $field . ":{required: true, email: true}";
                    } else {
                        $jsonRuleArray[] = $field . ":{required: true}";
                    }
                }
            }
            $rules = "{" . implode(", ", $jsonRuleArray) . "}";
        } else {
            $rules = "{Email:{required: true, email: true}}";
        }
        // set the custom script for this form
        Requirements::customScript(<<<JS
\t\t\t(function(\$) {
\t\t\t\tjQuery(document).ready(function() {
\t\t\t\t\tjQuery("#{$FormName}").validate({
\t\t\t\t\t\terrorClass: "required",
\t\t\t\t\t\tfocusCleanup: true,
\t\t\t\t\t\tmessages: {$messages},
\t\t\t\t\t\trules: {$rules}
\t\t\t\t\t});
\t\t\t\t});
\t\t\t})(jQuery);
JS
);
        return $form;
    }
Exemplo n.º 18
0
 /**
  * Get the fields needed by the forum module
  *
  * @param bool $showIdentityURL Should a field for an OpenID or an i-name
  *                              be shown (always read-only)?
  * @return FieldSet Returns a FieldSet containing all needed fields for
  *                  the registration of new users
  */
 function getForumFields($showIdentityURL = false, $addmode = false)
 {
     $gravatarText = DataObject::get_one("ForumHolder", "\"AllowGravatars\" = 1") ? '<small>' . _t('ForumRole.CANGRAVATAR', 'If you use Gravatars then leave this blank') . '</small>' : "";
     $personalDetailsFields = new CompositeField(new HeaderField("PersonalDetails", _t('ForumRole.PERSONAL', 'Personal Details')), new LiteralField("Blurb", "<p id=\"helpful\">" . _t('ForumRole.TICK', 'Tick the fields to show in public profile') . "</p>"), new TextField("Nickname", _t('ForumRole.NICKNAME', 'Nickname')), new CheckableOption("FirstNamePublic", new TextField("FirstName", _t('ForumRole.FIRSTNAME', 'First name'))), new CheckableOption("SurnamePublic", new TextField("Surname", _t('ForumRole.SURNAME', 'Surname'))), new CheckableOption("OccupationPublic", new TextField("Occupation", _t('ForumRole.OCCUPATION', 'Occupation')), true), new CheckableOption('CompanyPublic', new TextField('Company', _t('ForumRole.COMPANY', 'Company')), true), new CheckableOption('CityPublic', new TextField('City', _t('ForumRole.CITY', 'City')), true), new CheckableOption("CountryPublic", new CountryDropdownField("Country", _t('ForumRole.COUNTRY', 'Country')), true), new CheckableOption("EmailPublic", new EmailField("Email", _t('ForumRole.EMAIL', 'Email'))), new ConfirmedPasswordField("Password", _t('ForumRole.PASSWORD', 'Password')), new SimpleImageField("Avatar", _t('ForumRole.AVATAR', 'Upload avatar ') . ' ' . $gravatarText));
     // Don't show 'forum rank' at registration
     if (!$addmode) {
         $personalDetailsFields->push(new ReadonlyField("ForumRank", _t('ForumRole.RATING', 'User rating')));
     }
     $personalDetailsFields->setID('PersonalDetailsFields');
     $fieldset = new FieldSet($personalDetailsFields);
     if ($showIdentityURL) {
         $fieldset->insertBefore(new ReadonlyField('IdentityURL', _t('ForumRole.OPENIDINAME', 'OpenID/i-name')), 'Password');
         $fieldset->insertAfter(new LiteralField('PasswordOptionalMessage', '<p>' . _t('ForumRole.PASSOPTMESSAGE', 'Since you provided an OpenID respectively an i-name the password is optional. If you enter one, you will be able to log in also with your e-mail address.') . '</p>'), 'IdentityURL');
     }
     if ($this->owner->IsSuspended()) {
         $fieldset->insertAfter(new LiteralField('SuspensionNote', '<p class="message warning suspensionWarning">' . $this->ForumSuspensionMessage() . '</p>'), 'Blurb');
     }
     $this->owner->extend('updateForumFields', $fieldset);
     return $fieldset;
 }
 /**
  * returns an array of fields for the corporate account
  * @return Array
  */
 public function CorporateAddressFieldsArray($forCMS = false)
 {
     $fields = array();
     if ($this->owner->Title != $this->owner->CombinedCorporateGroupName()) {
         $fields[] = new ReadOnlyField("CombinedCorporateGroupName", _t("EcommerceCorporateGroup.FULLNAME", "Full Name"), $this->owner->CombinedCorporateGroupName());
     }
     foreach (self::$address_types as $fieldGroupPrefix => $fieldGroupTitle) {
         if ($forCMS) {
             $fields[] = new HeaderField($fieldGroupPrefix . "Header", $fieldGroupTitle, 4);
         } else {
             $composite = new CompositeField();
             $composite->setID($fieldGroupPrefix);
             $composite->push(new HeaderField($fieldGroupPrefix . "Header", $fieldGroupTitle, 4));
         }
         foreach (self::$address_fields as $name => $field) {
             $fieldClass = 'TextField';
             if ($field == 'Text') {
                 $fieldClass = 'TextareaField';
             } elseif ($name == 'Country') {
                 $fieldClass = 'CountryDropdownField';
             }
             if ($forCMS) {
                 $fields[] = new $fieldClass($fieldGroupPrefix . $name, $name);
             } else {
                 $composite->push(new $fieldClass($fieldGroupPrefix . $name, $name));
             }
         }
         if ($forCMS) {
             //
         } else {
             $fields[] = $composite;
         }
     }
     return $fields;
 }
Exemplo n.º 20
0
 function __construct($controller, $name)
 {
     Requirements::themedCSS('OrderForm');
     // 1) Member and shipping fields
     $member = Member::currentUser() ? Member::currentUser() : singleton('Member');
     $memberFields = new CompositeField($member->getEcommerceFields());
     $requiredFields = $member->getEcommerceRequiredFields();
     if (ShoppingCart::uses_different_shipping_address()) {
         $countryField = new DropdownField('ShippingCountry', 'Country', Geoip::getCountryDropDown(), EcommerceRole::findCountry());
         $shippingFields = new CompositeField(new HeaderField('Send goods to different address', 3), new LiteralField('ShippingNote', '<p class="warningMessage"><em>Your goods will be sent to the address below.</em></p>'), new LiteralField('Help', '<p>You can use this for gift giving. No billing information will be disclosed to this address.</p>'), new TextField('ShippingName', 'Name'), new TextField('ShippingAddress', 'Address'), new TextField('ShippingAddress2', ''), new TextField('ShippingCity', 'City'), $countryField, new HiddenField('UseShippingAddress', '', true), new FormAction_WithoutLabel('useMemberShippingAddress', 'Use Billing Address for Shipping'));
         $requiredFields[] = 'ShippingName';
         $requiredFields[] = 'ShippingAddress';
         $requiredFields[] = 'ShippingCity';
         $requiredFields[] = 'ShippingCountry';
     } else {
         $countryField = $memberFields->fieldByName('Country');
         $shippingFields = new FormAction_WithoutLabel('useDifferentShippingAddress', 'Use Different Shipping Address');
     }
     $countryField->addExtraClass('ajaxCountryField');
     $setCountryLinkID = $countryField->id() . '_SetCountryLink';
     $setContryLink = ShoppingCart_Controller::set_country_link();
     $memberFields->push(new HiddenField($setCountryLinkID, '', $setContryLink));
     $leftFields = new CompositeField($memberFields, $shippingFields);
     $leftFields->setID('LeftOrder');
     $rightFields = new CompositeField();
     $rightFields->setID('RightOrder');
     if (!$member->ID || $member->Password == '') {
         $rightFields->push(new HeaderField('Membership Details', 3));
         $rightFields->push(new LiteralField('MemberInfo', "<p class=\"message good\">If you are already a member, please <a href=\"Security/login?BackURL=" . CheckoutPage::find_link(true) . "/\">log in</a>.</p>"));
         $rightFields->push(new LiteralField('AccountInfo', "<p>Please choose a password, so you can login and check your order history in the future.</p><br/>"));
         $rightFields->push(new FieldGroup(new ConfirmedPasswordField('Password', 'Password')));
         $requiredFields[] = 'Password[_Password]';
         $requiredFields[] = 'Password[_ConfirmPassword]';
     }
     // 2) Payment fields
     $currentOrder = ShoppingCart::current_order();
     $total = '$' . number_format($currentOrder->Total(), 2);
     $paymentFields = Payment::combined_form_fields("{$total} " . $currentOrder->Currency(), $currentOrder->Total());
     foreach ($paymentFields as $field) {
         $rightFields->push($field);
     }
     if ($paymentRequiredFields = Payment::combined_form_requirements()) {
         $requiredFields = array_merge($requiredFields, $paymentRequiredFields);
     }
     // 3) Put all the fields in one FieldSet
     $fields = new FieldSet($leftFields, $rightFields);
     // 4) Terms and conditions field
     // If a terms and conditions page exists, we need to create a field to confirm the user has read it
     if ($controller->TermsPageID && ($termsPage = DataObject::get_by_id('Page', $controller->TermsPageID))) {
         $bottomFields = new CompositeField(new CheckboxField('ReadTermsAndConditions', "I agree to the terms and conditions stated on the <a href=\"{$termsPage->URLSegment}\" title=\"Read the shop terms and conditions for this site\">terms and conditions</a> page"));
         $bottomFields->setID('BottomOrder');
         $fields->push($bottomFields);
         $requiredFields[] = 'ReadTermsAndConditions';
     }
     // 5) Actions and required fields creation
     $actions = new FieldSet(new FormAction('processOrder', 'Place order and make payment'));
     $requiredFields = new CustomRequiredFields($requiredFields);
     // 6) Form construction
     parent::__construct($controller, $name, $fields, $actions, $requiredFields);
     // 7) Member details loading
     if ($member->ID) {
         $this->loadDataFrom($member);
     }
     // 8) Country field value update
     $currentOrder = ShoppingCart::current_order();
     $currentOrderCountry = $currentOrder->findShippingCountry(true);
     $countryField->setValue($currentOrderCountry);
 }
 /**
  *
  * @param Controller $controller
  * @param String
  */
 function __construct(Controller $controller, $name)
 {
     //requirements
     Requirements::javascript('ecommerce/javascript/EcomOrderForm.js');
     //set basics
     $order = ShoppingCart::current_order();
     $order->calculateOrderAttributes($force = false);
     $requiredFields = array();
     //  ________________  3) Payment fields - BOTTOM FIELDS
     $bottomFields = new CompositeField();
     $bottomFields->addExtraClass('bottomOrder');
     if ($order->Total() > 0) {
         $bottomFields->push(new HeaderField("PaymentHeader", _t("OrderForm.PAYMENT", "Payment"), 3));
         $paymentFields = EcommercePayment::combined_form_fields($order->getTotalAsMoney()->NiceLongSymbol(false), $order);
         foreach ($paymentFields as $paymentField) {
             $bottomFields->push($paymentField);
         }
         if ($paymentRequiredFields = EcommercePayment::combined_form_requirements($order)) {
             $requiredFields = array_merge($requiredFields, $paymentRequiredFields);
         }
     } else {
         $bottomFields->push(new HiddenField("PaymentMethod", "", ""));
     }
     //  ________________  4) FINAL FIELDS
     $finalFields = new CompositeField();
     $finalFields->addExtraClass('finalFields');
     $finalFields->push(new HeaderField('CompleteOrder', _t('OrderForm.COMPLETEORDER', 'Complete Order'), 3));
     // If a terms and conditions page exists, we need to create a field to confirm the user has read it
     if ($termsAndConditionsPage = CheckoutPage::find_terms_and_conditions_page()) {
         $checkoutPage = CheckoutPage::get()->First();
         if ($checkoutPage && $checkoutPage->TermsAndConditionsMessage) {
             $alreadyTicked = false;
             $requiredFields[] = 'ReadTermsAndConditions';
         } else {
             $alreadyTicked = true;
         }
         $finalFields->push(new CheckboxField('ReadTermsAndConditions', _t('OrderForm.AGREEWITHTERMS1', 'I have read and agree with the ') . ' <a href="' . $termsAndConditionsPage->Link() . '">' . trim(Convert::raw2xml($termsAndConditionsPage->Title)) . '</a>' . _t('OrderForm.AGREEWITHTERMS2', '.'), $alreadyTicked));
     }
     $textAreaField = new TextareaField('CustomerOrderNote', _t('OrderForm.CUSTOMERNOTE', 'Note / Question'));
     $finalFields->push($textAreaField);
     //  ________________  5) Put all the fields in one FieldList
     $fields = new FieldList($bottomFields, $finalFields);
     //  ________________  6) Actions and required fields creation + Final Form construction
     $actions = new FieldList(new FormAction('processOrder', _t('OrderForm.PROCESSORDER', 'Place order and make payment')));
     $validator = OrderForm_Validator::create($requiredFields);
     //we stick with standard validation here, because of the complexity and
     //hard-coded payment validation that is required
     parent::__construct($controller, $name, $fields, $actions, $validator);
     $this->setAttribute("autocomplete", "off");
     //extension point
     $this->extend('updateFields', $fields);
     $this->setFields($fields);
     $this->extend('updateActions', $actions);
     $this->setActions($actions);
     $this->extend('updateValidator', $validator);
     $this->setValidator($validator);
     //  ________________  7)  Load saved data
     if ($order) {
         $this->loadDataFrom($order);
     }
     //allow updating via decoration
     $this->extend('updateOrderForm', $this);
 }
 /**
  * Return the FieldSet used to edit a dynamic template in the CMS.
  */
 function getCMSFields()
 {
     $fileList = new DynamicTemplateFilesField("Files", "Files", $this);
     $titleField = $this->ID && $this->ID != "root" ? new TextField("Title", _t('Folder.TITLE')) : new HiddenField("Title");
     // delete files button
     if ($this->canEdit()) {
         $deleteButton = new InlineFormAction('deletemarked', _t('Folder.DELSELECTED', 'Delete selected files'), 'delete');
         $deleteButton->includeDefaultJS(false);
     } else {
         $deleteButton = new HiddenField('deletemarked');
     }
     // link file button
     if ($this->canEdit()) {
         $fileButtons = new CompositeField($linkFileButton = new InlineFormAction('linkfile', _t('DynamicTemplate.LINKFILE', 'Link file(s) from theme'), 'link'), $copyFileButton = new InlineFormAction('copyfile', _t('DynamicTemplate.COPYFILE', 'Copy file(s) from theme'), 'copy'), $newFileButton = new InlineFormAction('newfile', _t('DynamicTemplate.NEWFILE', 'New file'), 'newfile'));
         $linkFileButton->includeDefaultJS(false);
         $newFileButton->includeDefaultJS(false);
     } else {
         $fileButtons = new HiddenField('linkfile');
     }
     $propButtons = new CompositeField();
     //		$propButtons->push($exportButton = new InlineFormAction('exporttemplate', _t('DynamicTemplate.EXPORTTEMPLATE', 'Export'), 'export'));
     //		$exportButton->includeDefaultJS(false);
     //		if ($this->canEdit()) {
     //			$propButtons->push($saveButton = new InlineFormAction('savetemplate', _t('DynamicTemplate.SAVETEMPLATE', 'Save'), 'save'));
     //			$saveButton->includeDefaultJS(false);
     //		}
     if ($this->canDelete()) {
         $propButtons->push($deleteButton = new InlineFormAction('deletetemplate', _t('DynamicTemplate.DELETETEMPLATE', 'Delete'), 'delete'));
         $deleteButton->includeDefaultJS(false);
     }
     if (DynamicTemplateAdmin::tarball_available()) {
         $exportTarballButton = new InlineFormAction('exportastarball', _t('DynamicTemplate.EXPORT', 'Export as tarball'), 'exportastarball');
         $exportTarballButton->includeDefaultJS(false);
         $propButtons->push($exportTarballButton);
     }
     if (DynamicTemplateAdmin::zip_available()) {
         $exportZipButton = new InlineFormAction('exportaszip', _t('DynamicTemplate.EXPORT', 'Export as zip'), 'exportaszip');
         $exportZipButton->includeDefaultJS(false);
         $propButtons->push($exportZipButton);
     }
     $titleField = $this->ID && $this->ID != "root" ? new TextField("Title", _t('Folder.TITLE')) : new HiddenField("Title");
     if (!$this->canEdit()) {
         $titleField->setReadOnly(true);
     }
     $fields = new FieldSet(new HiddenField("Name"), new TabSet("Root", new Tab("Properties", _t('DynamicTemplate.PROPERTIESTAB', 'Properties'), $titleField, new ReadonlyField("URL", _t('Folder.URL', 'URL')), new ReadonlyField("Created", _t('Folder.CREATED', 'First Uploaded')), new ReadonlyField("LastEdited", _t('Folder.LASTEDITED', 'Last Updated')), $propButtons), new Tab("Files", _t('Folder.FILESTAB', "Files"), $fileList, $fileButtons, new HiddenField("FileIDs"), new HiddenField("DestFolderID")), new Tab("Upload", _t('Folder.UPLOADTAB', "Upload"), new LabelField('UploadPrompt', _t('DynamicTemplate.UPLOADPROMPT', 'Upload files to your template. Uploads will automatically be added to the right place.')), new LiteralField("UploadIframe", $this->getUploadIframe()))), new HiddenField("ID"));
     if (!$this->canEdit()) {
         $fields->removeFieldFromTab("Root", "Upload");
     }
     $this->extend('updateCMSFields', $fields);
     return $fields;
 }
Exemplo n.º 23
0
 function __construct($controller, $name)
 {
     //requirements
     Requirements::javascript('ecommerce/javascript/EcomOrderForm.js');
     //set basics
     $order = ShoppingCart::current_order();
     $order->calculateOrderAttributes($force = true);
     $requiredFields = array();
     //  ________________  3) Payment fields - BOTTOM FIELDS
     $bottomFields = new CompositeField();
     $bottomFields->setID('BottomOrder');
     $totalAsCurrencyObject = $order->TotalAsCurrencyObject();
     //should instead be $totalobj = $order->dbObject('Total');
     $totalOutstandingAsMoneyObject = $order->TotalAsMoneyObject();
     $paymentFields = Payment::combined_form_fields($totalOutstandingAsMoneyObject->Nice());
     foreach ($paymentFields as $paymentField) {
         if ($paymentField->class == "HeaderField") {
             $paymentField->setTitle(_t("OrderForm.MAKEPAYMENT", "Choose Payment"));
         }
         $bottomFields->push($paymentField);
     }
     if ($paymentRequiredFields = Payment::combined_form_requirements()) {
         $requiredFields = array_merge($requiredFields, $paymentRequiredFields);
     }
     //  ________________  4) FINAL FIELDS
     $finalFields = new CompositeField();
     $finalFields->setID('FinalFields');
     $finalFields->push(new HeaderField('CompleteOrder', _t('OrderForm.COMPLETEORDER', 'Complete Order'), 3));
     // If a terms and conditions page exists, we need to create a field to confirm the user has read it
     if ($termsAndConditionsPage = CheckoutPage::find_terms_and_conditions_page()) {
         $checkoutPage = DataObject::get_one("CheckoutPage");
         if ($checkoutPage && $checkoutPage->TermsAndConditionsMessage) {
             $alreadyTicked = false;
             $requiredFields[] = 'ReadTermsAndConditions';
         } else {
             $alreadyTicked = true;
         }
         $finalFields->push(new CheckboxField('ReadTermsAndConditions', _t('OrderForm.AGREEWITHTERMS1', 'I have read and agree with the ') . ' <a href="' . $termsAndConditionsPage->Link() . '">' . Convert::raw2xml($termsAndConditionsPage->Title) . '</a>' . _t('OrderForm.AGREEWITHTERMS2', '.'), $alreadyTicked));
     }
     $finalFields->push(new TextareaField('CustomerOrderNote', _t('OrderForm.CUSTOMERNOTE', 'Note / Question'), 7, 30));
     //  ________________  5) Put all the fields in one FieldSet
     $fields = new FieldSet($bottomFields, $finalFields);
     //  ________________  6) Actions and required fields creation + Final Form construction
     $actions = new FieldSet(new FormAction('processOrder', _t('OrderForm.PROCESSORDER', 'Place order and make payment')));
     $validator = new OrderForm_Validator($requiredFields);
     //we stick with standard validation here, because of the complexity and
     //hard-coded payment validation that is required
     $validator->setJavascriptValidationHandler("prototype");
     parent::__construct($controller, $name, $fields, $actions, $validator);
     //extensions need to be set after __construct
     if ($this->extend('updateFields', $fields) !== null) {
         $this->setFields($fields);
     }
     if ($this->extend('updateActions', $actions) !== null) {
         $this->setActions($actions);
     }
     if ($this->extend('updateValidator', $validator) !== null) {
         $this->setValidator($validator);
     }
     //  ________________  7)  Load saved data
     if ($order) {
         $this->loadDataFrom($order);
     }
     //allow updating via decoration
     $this->extend('updateOrderForm', $this);
 }
 /**
  * Puts together the fields for the Order Form (and other front-end purposes).
  * @param Member $member
  * @return FieldList
  **/
 public function getFields(Member $member = null)
 {
     $fields = parent::getEcommerceFields();
     $hasPreviousAddresses = false;
     if (EcommerceConfig::get("OrderAddress", "use_separate_shipping_address")) {
         $shippingFieldsHeader = new CompositeField(new HeaderField('SendGoodsToADifferentAddress', _t('OrderAddress.SENDGOODSTODIFFERENTADDRESS', 'Send goods to different address'), 3), new LiteralField('ShippingNote', '<p class="message warning">' . _t('OrderAddress.SHIPPINGNOTE', 'Your goods will be sent to the address below.') . '</p>'));
         if ($member) {
             if ($member->exists() && !$member->IsShopAdmin()) {
                 $this->FillWithLastAddressFromMember($member, true);
                 $addresses = $member->previousOrderAddresses($this->baseClassLinkingToOrder(), $this->ID, $onlyLastRecord = false, $keepDoubles = false);
                 //we want MORE than one here not just one.
                 if ($addresses->count() > 1) {
                     $hasPreviousAddresses = true;
                     $shippingFieldsHeader->push(SelectOrderAddressField::create('SelectShippingAddressField', _t('OrderAddress.SELECTBILLINGADDRESS', 'Select Shipping Address'), $addresses));
                 }
             }
             $shippingFields = new CompositeField(new TextField('ShippingFirstName', _t('OrderAddress.FIRSTNAME', 'First Name')), new TextField('ShippingSurname', _t('OrderAddress.SURNAME', 'Surname')));
         } else {
             $shippingFields = new CompositeField(new TextField('ShippingFirstName', _t('OrderAddress.FIRSTNAME', 'First Name')), new TextField('ShippingSurname', _t('OrderAddress.SURNAME', 'Surname')));
         }
         $shippingFields->push(new TextField('ShippingPhone', _t('OrderAddress.PHONE', 'Phone')));
         //$shippingFields->push(new TextField('ShippingMobilePhone', _t('OrderAddress.MOBILEPHONE','Mobile Phone')));
         $mappingArray = $this->Config()->get("fields_to_google_geocode_conversion");
         if (is_array($mappingArray) && count($mappingArray)) {
             if (!class_exists("GoogleAddressField")) {
                 user_error("You must install the Sunny Side Up google_address_field module OR remove entries from: ShippingAddress.fields_to_google_geocode_conversion");
             }
             $shippingFields->push($shippingEcommerceGeocodingField = new GoogleAddressField('ShippingEcommerceGeocodingField', _t('OrderAddress.Find_Address', 'Find address'), Session::get("ShippingEcommerceGeocodingFieldValue")));
             $shippingEcommerceGeocodingField->setFieldMap($mappingArray);
             //$shippingFields->push(new HiddenField('ShippingAddress2'));
             //$shippingFields->push(new HiddenField('ShippingCity'));
         } else {
         }
         //$shippingFields->push(new TextField('ShippingPrefix', _t('OrderAddress.PREFIX','Title (e.g. Ms)')));
         $shippingFields->push(new TextField('ShippingAddress', _t('OrderAddress.ADDRESS', 'Address')));
         $shippingFields->push(new TextField('ShippingAddress2', _t('OrderAddress.ADDRESS2', '')));
         $shippingFields->push(new TextField('ShippingCity', _t('OrderAddress.CITY', 'Town')));
         $shippingFields->push($this->getRegionField("ShippingRegionID", "ShippingRegionCode"));
         $shippingFields->push($this->getPostalCodeField("ShippingPostalCode"));
         $shippingFields->push($this->getCountryField("ShippingCountry"));
         $this->makeSelectedFieldsReadOnly($shippingFields);
         $shippingFieldsHeader->addExtraClass("shippingFieldsHeader");
         $shippingFields->addExtraClass("orderAddressHolder");
         $fields->push($shippingFieldsHeader);
         $shippingFields->addExtraClass('shippingFields');
         $fields->push($shippingFields);
     }
     $this->extend('augmentEcommerceShippingAddressFields', $fields);
     return $fields;
 }
 /**
  *
  * @param Controller
  * @param String
  */
 function __construct(Controller $controller, $name)
 {
     //set basics
     $requiredFields = array();
     //requirements
     Requirements::javascript('ecommerce/javascript/EcomOrderFormAddress.js');
     // LEAVE HERE - NOT EASY TO INCLUDE VIA TEMPLATE
     if (EcommerceConfig::get("OrderAddress", "use_separate_shipping_address")) {
         Requirements::javascript('ecommerce/javascript/EcomOrderFormShipping.js');
         // LEAVE HERE - NOT EASY TO INCLUDE VIA TEMPLATE
     }
     //  ________________ 1) Order + Member + Address fields
     //find member
     $this->order = ShoppingCart::current_order();
     $this->orderMember = $this->order->CreateOrReturnExistingMember(false);
     $this->loggedInMember = Member::currentUser();
     //strange security situation...
     if ($this->orderMember->exists() && $this->loggedInMember) {
         if ($this->orderMember->ID != $this->loggedInMember->ID) {
             if (!$this->loggedInMember->IsShopAdmin()) {
                 $this->loggedInMember->logOut();
             }
         }
     }
     $addressFieldsBilling = new FieldList();
     //member fields
     if ($this->orderMember) {
         $memberFields = $this->orderMember->getEcommerceFields();
         $requiredFields = array_merge($requiredFields, $this->orderMember->getEcommerceRequiredFields());
         $addressFieldsBilling->merge($memberFields);
     }
     //billing address field
     $billingAddress = $this->order->CreateOrReturnExistingAddress("BillingAddress");
     $billingAddressFields = $billingAddress->getFields($this->orderMember);
     $requiredFields = array_merge($requiredFields, $billingAddress->getRequiredFields());
     $addressFieldsBilling->merge($billingAddressFields);
     //shipping address field
     $addressFieldsShipping = null;
     if (EcommerceConfig::get("OrderAddress", "use_separate_shipping_address")) {
         $addressFieldsShipping = new FieldList();
         //add the important CHECKBOX
         $useShippingAddressField = new FieldList(new CheckboxField("UseShippingAddress", _t("OrderForm.USESHIPPINGADDRESS", "Use an alternative shipping address")));
         $addressFieldsShipping->merge($useShippingAddressField);
         //now we can add the shipping fields
         $shippingAddress = $this->order->CreateOrReturnExistingAddress("ShippingAddress");
         $shippingAddressFields = $shippingAddress->getFields($this->orderMember);
         //we have left this out for now as it was giving a lot of grief...
         //$requiredFields = array_merge($requiredFields, $shippingAddress->getRequiredFields());
         //finalise left fields
         $addressFieldsShipping->merge($shippingAddressFields);
     }
     $leftFields = new CompositeField($addressFieldsBilling);
     $leftFields->addExtraClass('leftOrderBilling');
     $allLeftFields = new CompositeField($leftFields);
     $allLeftFields->addExtraClass('leftOrder');
     if ($addressFieldsShipping) {
         $leftFieldsShipping = new CompositeField($addressFieldsShipping);
         $leftFieldsShipping->addExtraClass('leftOrderShipping');
         $allLeftFields->push($leftFieldsShipping);
     }
     //  ________________  2) Log in / vs Create Account fields - RIGHT-HAND-SIDE fields
     $rightFields = new CompositeField();
     $rightFields->addExtraClass('rightOrder');
     //to do: simplify
     if (EcommerceConfig::get("EcommerceRole", "allow_customers_to_setup_accounts")) {
         if ($this->orderDoesNotHaveFullyOperationalMember()) {
             //general header
             if (!$this->loggedInMember) {
                 $rightFields->push(new LiteralField('MemberInfo', '<p class="message good">' . _t('OrderForm.MEMBERINFO', 'If you already have an account then please') . " <a href=\"Security/login/?BackURL=/" . urlencode(implode("/", $controller->getURLParams())) . "\">" . _t('OrderForm.LOGIN', 'log in') . '</a>.</p>'));
             }
         } else {
             if ($this->loggedInMember) {
                 $rightFields->push(new LiteralField('LoginNote', "<p class=\"message good\">" . _t("Account.LOGGEDIN", "You are logged in as ") . Convert::raw2xml($this->loggedInMember->FirstName) . ' ' . Convert::raw2xml($this->loggedInMember->Surname) . ' (' . Convert::raw2xml($this->loggedInMember->Email) . ').' . ' <a href="/Security/logout/">' . _t("Account.LOGOUTNOW", "Log out?") . '</a>' . '</p>'));
             }
         }
         if ($this->orderMember->exists()) {
             if ($this->loggedInMember) {
                 if ($this->loggedInMember->ID != $this->orderMember->ID) {
                     $rightFields->push(new LiteralField('OrderAddedTo', "<p class=\"message good\">" . _t("Account.ORDERADDEDTO", "Order will be added to ") . Convert::raw2xml($this->orderMember->FirstName) . ' ' . Convert::raw2xml($this->orderMember->Surname) . ' (' . Convert::raw2xml($this->orderMember->Email) . ').</p>'));
                 }
             }
         }
     }
     //  ________________  5) Put all the fields in one FieldList
     $fields = new FieldList($rightFields, $allLeftFields);
     //  ________________  6) Actions and required fields creation + Final Form construction
     $nextButton = new FormAction('saveAddress', _t('OrderForm.NEXT', 'Next'));
     $nextButton->addExtraClass("next");
     $actions = new FieldList($nextButton);
     $validator = OrderFormAddress_Validator::create($requiredFields);
     parent::__construct($controller, $name, $fields, $actions, $validator);
     $this->setAttribute("autocomplete", "off");
     //extensions need to be set after __construct
     //extension point
     $this->extend('updateFields', $fields);
     $this->setFields($fields);
     $this->extend('updateActions', $actions);
     $this->setActions($actions);
     $this->extend('updateValidator', $validator);
     $this->setValidator($validator);
     //this needs to come after the extension calls
     foreach ($validator->getRequired() as $requiredField) {
         $field = $fields->dataFieldByName($requiredField);
         if ($field) {
             $field->addExtraClass("required");
         }
     }
     //  ________________  7)  Load saved data
     //we do this first so that Billing and Shipping Address can override this...
     if ($this->orderMember) {
         $this->loadDataFrom($this->orderMember);
     }
     if ($this->order) {
         $this->loadDataFrom($this->order);
         if ($billingAddress) {
             $this->loadDataFrom($billingAddress);
         }
         if (EcommerceConfig::get("OrderAddress", "use_separate_shipping_address")) {
             if ($shippingAddress) {
                 $this->loadDataFrom($shippingAddress);
             }
         }
     }
     //allow updating via decoration
     $oldData = Session::get("FormInfo.{$this->FormName()}.data");
     if ($oldData && (is_array($oldData) || is_object($oldData))) {
         $this->loadDataFrom($oldData);
     }
     $this->extend('updateOrderFormAddress', $this);
 }
Exemplo n.º 26
0
 /**
  * Add a new child field to the end of the set.
  *
  * @param FormField $field
  */
 public function push(FormField $field)
 {
     if ($field instanceof Tab || $field instanceof TabSet) {
         $field->setTabSet($this);
     }
     parent::push($field);
 }
Exemplo n.º 27
0
 /**
  * @param boolean $geoDefaults
  * @return \FieldList
  */
 public function getAddressFields($geoDefaults = true)
 {
     $fields = new CompositeField();
     $localityValue = $this->owner->Locality;
     $countryCode = $this->owner->CountryCode;
     $postalCodeValue = $this->owner->PostalCode;
     if ((!$localityValue || !$countryCode || !$postalCodeValue) && $geoDefaults) {
         $addressFromIp = Geocoder::geocodeIp(null, 'city', true);
         if ($addressFromIp) {
             if (!$localityValue) {
                 $localityValue = (string) $addressFromIp->getLocality();
             }
             if (!$countryCode) {
                 $countryCode = (string) $addressFromIp->getCountryCode();
             }
             if (!$postalCodeValue) {
                 $postalCodeValue = (string) $addressFromIp->getPostalCode();
             }
         }
     }
     $longWidth = 300;
     $shortWidth = 80;
     $streetname = new TextField('StreetName', _t('GeoMemberExtension.STREETNAME', 'Street Name'), $this->owner->StreetName);
     $streetname->setAttribute('placeholder', _t('GeoMemberExtension.STREETNAME', 'Street Name'));
     $streetname->setTitle('');
     $streetname->setAttribute('style', 'width:' . $longWidth . 'px');
     $streetnumber = new TextField('StreetNumber', _t('GeoMemberExtension.STREETNUMBER', 'Street Number'), $this->owner->StreetNumber);
     $streetnumber->setAttribute('placeholder', _t('GeoMemberExtension.STREETNUMBERPLACEHOLDER', 'N°'));
     $streetnumber->setTitle('');
     $streetnumber->setAttribute('style', 'width:' . $shortWidth . 'px');
     $fields->push($street = new FieldGroup($streetname, $streetnumber));
     $street->setTitle(_t('GeoMemberExtension.STREET', 'Street'));
     $street->setFieldHolderTemplate('AddressFieldHolder');
     $postalCodeClass = 'TextField';
     if (class_exists('PostCodeField')) {
         $postalCodeClass = 'PostCodeField';
     }
     $postcode = new $postalCodeClass('PostalCode', _t('GeoMemberExtension.POSTCODE', 'Postal Code'), $postalCodeValue);
     $postcode->setAttribute('placeholder', _t('GeoMemberExtension.POSTCODEPLACEHOLDER', 'Postcode'));
     $postcode->setTitle('');
     $postcode->setAttribute('style', 'width:' . $shortWidth . 'px');
     $locality = new TextField('Locality', _t('GeoMemberExtension.CITY', 'City'), $localityValue);
     $locality->setAttribute('placeholder', _t('GeoMemberExtension.CITY', 'City'));
     $locality->setTitle('');
     $locality->setAttribute('style', 'width:' . $longWidth . 'px');
     $fields->push($localitygroup = new FieldGroup($postcode, $locality));
     $localitygroup->setTitle(_t('GeoMemberExtension.LOCALITY', 'Locality'));
     $localitygroup->setFieldHolderTemplate('AddressFieldHolder');
     // Support some countries administrative areas
     if ($this->owner->CountryCode == 'FR') {
         $fields->push(new FrenchDepartmentField());
     }
     if ($this->owner->CountryCode == 'BE') {
         $fields->push(new BelgianProvinceField());
     }
     $label = _t('GeoMemberExtension.COUNTRY', 'Country');
     $fields->push($countrydd = new CountryDropdownField('CountryCode', _t('GeoMemberExtension.COUNTRY', 'Country'), self::getCountryList(), $countryCode));
     $countrydd->setEmptyString('');
     return $fields;
 }
 /**
  * Uninstall domain form
  *
  * @return FormField
  */
 public function UninstallDomainForm()
 {
     $verified = $this->SendingDomainVerified();
     $spfVerified = true;
     $dkimVerified = true;
     if ($verified) {
         if ($verified['spf_status'] == 'invalid') {
             $spfVerified = false;
         }
         if ($verified['dkim_status'] == 'invalid') {
             $dkimVerified = false;
         }
     }
     $domain = $this->getDomain();
     $fields = new CompositeField();
     if ($spfVerified && $dkimVerified) {
         $fields->push(new LiteralField('Info', '<div class="message good">' . _t('SparkPostAdmin.DomainInstalled', 'Domain {domain} is installed.', ['domain' => $domain]) . '</div>'));
     } else {
         $fields->push(new LiteralField('Info', '<div class="message warning">' . _t('SparkPostAdmin.DomainInstalledBut', 'Domain {domain} is installed, but is not properly configured. SPF records : {spf}. Domain key (DKIM) : {dkim}. Please check your dns zone.', ['domain' => $domain, 'spf' => $spfVerified ? 'OK' : 'NOT OK', 'dkim' => $dkimVerified ? 'OK' : 'NOT OK']) . '</div>'));
     }
     $fields->push(new LiteralField('doUninstallHook', '<a class="ss-ui-button" href="' . $this->Link('doUninstallHook') . '">' . _t('SparkPostAdmin.DOUNINSTALLDOMAIN', 'Uninstall domain') . '</a>'));
     return $fields;
 }
    public function Form()
    {
        if ($this->URLParams['Action'] === 'completed' || $this->URLParams['Action'] == 'submitted') {
            return;
        }
        $dataFields = singleton('Recipient')->getFrontEndFields()->dataFields();
        if ($this->CustomLabel) {
            $customLabel = Convert::json2array($this->CustomLabel);
        }
        $fields = array();
        if ($this->Fields) {
            $fields = explode(",", $this->Fields);
        }
        $recipientInfoSection = new CompositeField();
        $requiredFields = Convert::json2array($this->Required);
        if (!empty($fields)) {
            foreach ($fields as $field) {
                if (isset($dataFields[$field]) && $dataFields[$field]) {
                    if (is_a($dataFields[$field], "ImageField")) {
                        if (isset($requiredFields[$field])) {
                            $title = $dataFields[$field]->Title() . " * ";
                        } else {
                            $title = $dataFields[$field]->Title();
                        }
                        $dataFields[$field] = new SimpleImageField($dataFields[$field]->Name(), $title);
                    } else {
                        if (isset($requiredFields[$field])) {
                            if (isset($customLabel[$field])) {
                                $title = $customLabel[$field] . " * ";
                            } else {
                                $title = $dataFields[$field]->Title() . " * ";
                            }
                        } else {
                            if (isset($customLabel[$field])) {
                                $title = $customLabel[$field];
                            } else {
                                $title = $dataFields[$field]->Title();
                            }
                        }
                        $dataFields[$field]->setTitle($title);
                    }
                    $recipientInfoSection->push($dataFields[$field]);
                }
            }
        }
        $formFields = new FieldList(new HeaderField("CustomisedHeading", $this->owner->CustomisedHeading), $recipientInfoSection);
        $recipientInfoSection->setID("MemberInfoSection");
        if ($this->MailingLists) {
            $mailinglists = DataObject::get("MailingList", "ID IN (" . $this->MailingLists . ")");
        }
        if (isset($mailinglists) && $mailinglists && $mailinglists->count() > 1) {
            $newsletterSection = new CompositeField(new LabelField("Newsletters", _t("SubscriptionPage.To", "Subscribe to:"), 4), new CheckboxSetField("NewsletterSelection", "", $mailinglists, $mailinglists->getIDList()));
            $formFields->push($newsletterSection);
        }
        $buttonTitle = $this->SubmissionButtonText;
        $actions = new FieldList(new FormAction('doSubscribe', $buttonTitle));
        if (!empty($requiredFields)) {
            $required = new RequiredFields($requiredFields);
        } else {
            $required = null;
        }
        $form = new Form($this, "Form", $formFields, $actions, $required);
        // using jQuery to customise the validation of the form
        $FormName = $form->FormName();
        $validationMessage = Convert::json2array($this->ValidationMessage);
        if (!empty($requiredFields)) {
            $jsonRuleArray = array();
            $jsonMessageArray = array();
            foreach ($requiredFields as $field => $true) {
                if ($true) {
                    if (isset($validationMessage[$field]) && $validationMessage[$field]) {
                        $error = $validationMessage[$field];
                    } else {
                        $label = isset($customLabel[$field]) ? $customLabel[$field] : $dataFields[$field]->Title();
                        $error = sprintf(_t('Newsletter.PleaseEnter', "Please enter your %s field"), $label);
                    }
                    if ($field === 'Email') {
                        $jsonRuleArray[] = $field . ":{required: true, email: true}";
                        $message = <<<JSON
{
required: "<span class='exclamation'></span><span class='validation-bubble'>
{$error}<span></span></span>",
email: "<span class='exclamation'></span><span class='validation-bubble'>
Please enter a valid email address<span></span></span>"
}
JSON;
                        $jsonMessageArray[] = $field . ":{$message}";
                    } else {
                        $jsonRuleArray[] = $field . ":{required: true}";
                        $message = <<<HTML
<span class='exclamation'></span><span class='validation-bubble'>{$error}<span></span></span>
HTML;
                        $jsonMessageArray[] = $field . ":\"{$message}\"";
                    }
                }
            }
            $rules = "{" . implode(", ", $jsonRuleArray) . "}";
            $messages = "{" . implode(",", $jsonMessageArray) . "}";
        } else {
            $rules = "{Email:{required: true, email: true}}";
            $emailAddrMsg = _t('Newsletter.ValidEmail', 'Please enter your email address');
            $messages = <<<JS
{Email: {
required: "<span class='exclamation'></span><span class='validation-bubble'>
{$emailAddrMsg}<span></span></span>",
email: "<span class='exclamation'></span><span class='validation-bubble'>
{$emailAddrMsg}<span></span></span>"
}}
JS;
        }
        // set the custom script for this form
        Requirements::customScript(<<<JS
(function(\$) {
\tjQuery(document).ready(function() {
\t\t\$("#{$FormName}").validate({
\t\t\terrorPlacement: function(error, element) {
\t\t\t\terror.insertAfter(element);
\t\t\t},
\t\t\tfocusCleanup: true,
\t\t\tmessages: {$messages},
\t\t\trules: {$rules}
\t\t});
\t});
})(jQuery);
JS
);
        return $form;
    }
Exemplo n.º 30
0
 /**
  *@return Fieldset
  **/
 public function getFields($member = null)
 {
     $fields = parent::getEcommerceFields();
     $fields->push(new HeaderField('BillingDetails', _t('OrderAddress.BILLINGDETAILS', 'Billing Details'), 3));
     if ($member) {
         if ($member->exists()) {
             $addresses = $this->previousAddressesFromMember($member);
             if ($addresses) {
                 if ($addresses->count() > 1) {
                     $fields->push(new SelectOrderAddressField('SelectBillingAddressField', _t('OrderAddress.SELECTBILLINGADDRESS', 'Select Billing Address'), $addresses));
                 }
             }
         }
         $billingFields = new CompositeField(new EmailField('Email', _t('OrderAddress.EMAIL', 'Email')), new TextField('FirstName', _t('OrderAddress.FIRSTNAME', 'First Name')), new TextField('Surname', _t('OrderAddress.SURNAME', 'Surname')));
     } else {
         $billingFields = new CompositeField(new EmailField('Email', _t('OrderAddress.EMAIL', 'Email')), new TextField('FirstName', _t('OrderAddress.FIRSTNAME', 'First Name')), new TextField('Surname', _t('OrderAddress.SURNAME', 'Surname')));
     }
     $billingFields->push(new TextField('Prefix', _t('OrderAddress.PREFIX', 'Title (e.g. Ms)')));
     $billingFields->push(new TextField('Address', _t('OrderAddress.ADDRESS', 'Address')));
     $billingFields->push(new TextField('Address2', _t('OrderAddress.ADDRESS2', '&nbsp;')));
     $billingFields->push(new TextField('City', _t('OrderAddress.CITY', 'Town')));
     $billingFields->push($this->getPostalCodeField("PostalCode"));
     $billingFields->push($this->getRegionField("RegionID"));
     $billingFields->push($this->getCountryField("Country"));
     $billingFields->push(new TextField('Phone', _t('OrderAddress.PHONE', 'Phone')));
     $billingFields->push(new TextField('MobilePhone', _t('OrderAddress.MOBILEPHONE', 'Mobile Phone')));
     $billingFields->SetID('BillingFields');
     $billingFields->addExtraClass("orderAddressHolder");
     $this->makeSelectedFieldsReadOnly($billingFields);
     $fields->push($billingFields);
     $this->extend('augmentEcommerceBillingAddressFields', $fields);
     return $fields;
 }