/**
  * @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 EnquiryForm()
    {
        if (!Email::validEmailAddress($this->EmailTo) || !Email::validEmailAddress($this->EmailFrom)) {
            return false;
        }
        if (!$this->EmailSubject) {
            $this->EmailSubject = 'Website Enquiry';
        }
        $elements = $this->EnquiryFormFields();
        if ($elements->count() == 0) {
            return false;
        }
        /* Build the fieldlist */
        $fields = new FieldList();
        $validator = new RequiredFields();
        $jsValidator = array();
        foreach ($elements as $el) {
            $key = $this->keyGen($el->FieldName, $el->SortOrder);
            $field = false;
            $type = false;
            if ($el->FieldType == 'Text') {
                if ($el->FieldOptions == 1) {
                    $field = new TextField($key, htmlspecialchars($el->FieldName));
                } else {
                    $field = new TextareaField($key, htmlspecialchars($el->FieldName));
                    $field->setRows($el->FieldOptions);
                }
            } else {
                if ($el->FieldType == 'Email') {
                    $field = new EmailField($key, htmlspecialchars($el->FieldName));
                } else {
                    if ($el->FieldType == 'Select') {
                        $options = preg_split('/\\n\\r?/', $el->FieldOptions, -1, PREG_SPLIT_NO_EMPTY);
                        if (count($options) > 0) {
                            $tmp = array();
                            foreach ($options as $o) {
                                $tmp[trim($o)] = trim($o);
                            }
                            $field = new DropdownField($key, htmlspecialchars($el->FieldName), $tmp);
                            $field->setEmptyString('[ Please Select ]');
                        }
                    } else {
                        if ($el->FieldType == 'Checkbox') {
                            $options = preg_split('/\\n\\r?/', $el->FieldOptions, -1, PREG_SPLIT_NO_EMPTY);
                            if (count($options) > 0) {
                                $tmp = array();
                                foreach ($options as $o) {
                                    $tmp[trim($o)] = trim($o);
                                }
                                $field = new CheckboxSetField($key, htmlspecialchars($el->FieldName), $tmp);
                            }
                        } else {
                            if ($el->FieldType == 'Radio') {
                                $options = preg_split('/\\n\\r?/', $el->FieldOptions, -1, PREG_SPLIT_NO_EMPTY);
                                if (count($options) > 0) {
                                    $tmp = array();
                                    foreach ($options as $o) {
                                        $tmp[trim($o)] = trim($o);
                                    }
                                    $field = new OptionsetField($key, htmlspecialchars($el->FieldName), $tmp);
                                }
                            } else {
                                if ($el->FieldType == 'Header') {
                                    if ($el->FieldOptions) {
                                        $field = new LiteralField(htmlspecialchars($el->FieldName), '<h4>' . htmlspecialchars($el->FieldName) . '</h4>
						<p class="note">' . nl2br(htmlspecialchars($el->FieldOptions)) . '</p>');
                                    } else {
                                        $field = new HeaderField(htmlspecialchars($el->FieldName), 4);
                                    }
                                } else {
                                    if ($el->FieldType == 'Note') {
                                        if ($el->FieldOptions) {
                                            $field = new LiteralField(htmlspecialchars($el->FieldName), '<p class="note">' . nl2br(htmlspecialchars($el->FieldOptions)) . '</p>');
                                        } else {
                                            $field = new LiteralField(htmlspecialchars($el->FieldName), '<p class="note">' . htmlspecialchars($el->FieldName) . '</p>');
                                        }
                                    }
                                }
                            }
                        }
                    }
                }
            }
            if ($field) {
                if ($el->RequiredField == 1) {
                    $field->addExtraClass('required');
                    /* Add "Required" next to field" */
                    $validator->addRequiredField($key);
                    $jsValidator[$key] = $el->FieldType;
                }
                if ($el->PlaceholderText) {
                    $field->setAttribute('placeholder', $el->PlaceholderText);
                }
                $fields->push($field);
            }
        }
        if ($this->AddCaptcha) {
            $label = $this->CaptchaLabel;
            $field = new CaptchaField('CaptchaImage', $label);
            $field->addExtraClass('required');
            $validator->addRequiredField('CaptchaImage');
            $jsValidator['CaptchaImage'] = 'Text';
            if ($this->CaptchaHelp) {
                $field->setRightTitle('<span id="CaptchaHelp">' . htmlspecialchars($this->CaptchaHelp) . '</span>');
            }
            $fields->push($field);
        }
        $actions = new FieldList(new FormAction('SendEnquiryForm', $this->EmailSubmitButtonText));
        Requirements::customScript("var EnquiryFormValidator=" . json_encode($jsValidator) . ';');
        Requirements::javascript(basename(dirname(dirname(__FILE__))) . "/templates/javascript/EnquiryForm.js");
        $form = new Form($this, 'EnquiryForm', $fields, $actions, $validator);
        return $form;
    }