当前位置: 首页>>代码示例>>PHP>>正文


PHP LiteralField::setAttribute方法代码示例

本文整理汇总了PHP中LiteralField::setAttribute方法的典型用法代码示例。如果您正苦于以下问题:PHP LiteralField::setAttribute方法的具体用法?PHP LiteralField::setAttribute怎么用?PHP LiteralField::setAttribute使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在LiteralField的用法示例。


在下文中一共展示了LiteralField::setAttribute方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。

示例1: EnquiryForm

    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');
//.........这里部分代码省略.........
开发者ID:helpfulrobot,项目名称:axllent-silverstripe-enquiry-page,代码行数:101,代码来源:EnquiryPage.php


注:本文中的LiteralField::setAttribute方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。