@see Zend_Form::addElement

We have to override this, because we have to set some special decorators
on a per-element basis (checkboxes and submit buttons have different
decorators than other elements)
339833
public function addElement($element, $name = null, $options = null)
	{
		parent::addElement($element, $name, $options);

		if(!$element instanceof Zend_Form_Element && $name != null)
		{
			$element = $this->getElement($name);
		}
		// An existing instance of a form element was added to the form
		// We need to reset its decorators
		else
		{
			$element->clearDecorators();
			$element->setDecorators($this->_getElementDecorators());
		}

		if($element instanceof Zend_Form_Element_File)
		{
			$decorators = $this->_getElementDecorators();
			$decorators[0] = "File";
			$element->setDecorators($decorators);
		}

		// Special style for Zend
		if($element instanceof Zend_Form_Element_Submit
			|| $element instanceof Zend_Form_Element_Reset
			|| $element instanceof Zend_Form_Element_Button)
		{
			$class = "";

			if($element instanceof Zend_Form_Element_Submit
				&& !($element instanceof Zend_Form_Element_Reset)
			 	&& !($element instanceof Zend_Form_Element_Button))
			{
				$class = "btn-primary";
			}

			$element->setAttrib("class", trim("btn $class " . $element->getAttrib("class")));
			$element->removeDecorator("Label");
			$element->removeDecorator("outerwrapper");
			$element->removeDecorator("innerwrapper");

			$this->_addActionsDisplayGroupElement($element);

			//$element->addDecorator(array(
				//"outerwrapper" => "HtmlTag"), array("tag" => "div", "class" => "actions")
			//);
		}

		if($element instanceof Zend_Form_Element_Checkbox)
		{
			$element->setDecorators(array(
				array(array("labelopening" => "HtmlTag"), array("tag" => "label", "class" => "checkbox", "id" => $element->getId()."-label", "for" => $element->getName(), "openOnly" => true)),
				"ViewHelper",
				array("Checkboxlabel"),
				array(array("labelclosing" => "HtmlTag"), array("tag" => "label", "closeOnly" => true)),
				array("Errors", array("placement" => "append")),
				array("Description", array("tag" => "span", "class" => "help-block")),
				array(array("innerwrapper" => "HtmlTag"), array("tag" => "div", "class" => "controls")),
				array(array("outerwrapper" => "HtmlTag"), array("tag" => "div", "class" => "control-group"))
			));
		}

		if($element instanceof Zend_Form_Element_Radio
			|| $element instanceof Zend_Form_Element_MultiCheckbox)
		{
			$multiOptions = array();
			foreach($element->getMultiOptions() as $value => $label)
			{
				$multiOptions[$value] = " ".$label;
			}

			$element->setMultiOptions($multiOptions);

			$element->setAttrib("labelclass", "checkbox");

			if($element->getAttrib("inline"))
			{
				$element->setAttrib("labelclass", "checkbox inline");
			}

			if ($element instanceof Zend_Form_Element_Radio)
			{
				$element->setAttrib("labelclass", "radio");
			}

			if($element->getAttrib("inline"))
			{
				$element->setAttrib("labelclass", "radio inline");
			}

			$element->setOptions(array("separator" => ""));
			$element->setDecorators(array(
				"ViewHelper",
				array("Errors", array("placement" => "append")),
				array("Description", array("tag" => "span", "class" => "help-block")),
				array(array("innerwrapper" => "HtmlTag"), array("tag" => "div", "class" => "controls")),
				array("Label", array("class" => "control-label")),
				array(array("outerwrapper" => "HtmlTag"), array("tag" => "div", "class" => "control-group"))
			));
		}

		if($element instanceof Zend_Form_Element_Hidden)
		{
			$element->setDecorators(array("ViewHelper"));
		}
		
		if($element instanceof Zend_Form_Element_Textarea && !$element->getAttrib('rows'))
		{
			$element->setAttrib('rows', '3');
		}
		
		if($element instanceof Zend_Form_Element_Captcha)
		{
			$element->removeDecorator("viewhelper");
		}

        return $this;
	}
1212895
protected function add_defaults() {
        $mform =& $this->_form;
        $strrequired = get_string('required');

        $mform->addElement('hidden', 'edit',  ($this->instance) ? $this->instance->id : 0);
        $mform->setType('edit', PARAM_INT);
        $mform->addElement('hidden', 'new',   $this->plugin);
        $mform->setType('new', PARAM_ALPHANUMEXT);
        $mform->addElement('hidden', 'plugin', $this->plugin);
        $mform->setType('plugin', PARAM_PLUGIN);
        $mform->addElement('hidden', 'typeid', $this->typeid);
        $mform->setType('typeid', PARAM_INT);
        $mform->addElement('hidden', 'contextid', $this->contextid);
        $mform->setType('contextid', PARAM_INT);

        $mform->addElement('text', 'name', get_string('name'), 'maxlength="100" size="30"');
        $mform->addRule('name', $strrequired, 'required', null, 'client');
        $mform->setType('name', PARAM_TEXT);
    }
1323965
protected function definition() {
        $mform = $this->_form;

        $mform->addElement('hidden', 'id');
        $mform->setType('id', PARAM_INT);

        $mform->addElement('header', 'filterheader', get_string('filter'));
        $opts = ['optional' => true];
        $mform->addElement('date_selector', 'filterstartdate', get_string('from'), $opts);
        $mform->addElement('date_selector', 'filterenddate', get_string('to'), $opts);

        $mform->setExpanded('filterheader', false);

        // Add the filter/cancel buttons (without 'closeHeaderBefore', so they collapse with the filter).
        $buttonarray = [
            $mform->createElement('submit', 'submitbutton', get_string('filter')),
            $mform->createElement('cancel'),
        ];
        $mform->addGroup($buttonarray, 'buttonar', '', [' '], false);
    }
285673
protected function addElement_checkbox ($name, $label, $customElementConfig=array())
    {
        $defaultElementConfig = array(
            'name'       => $name,
            'attributes' => array(
                'id'         => $name,
            ),
            'options'    => array(
                'label'      => $label,
            ),
        );
        $elementConfig = array_replace_recursive(
            $defaultElementConfig,
            $customElementConfig
        );

        $this->addElement_checkbox_configArray($elementConfig);
    }
110212
public function initElements()
    {
        

    	$labelElt = tao_helpers_form_FormFactory::getElement('label', 'Textbox');
		$labelElt->setDescription(__('Name'));
		$labelElt->addValidator(tao_helpers_form_FormFactory::getValidator('NotEmpty'));
		$this->form->addElement($labelElt);

		$sizeElt = tao_helpers_form_FormFactory::getElement('size', 'Textbox');
		$sizeElt->setDescription(__('Number of elements'));
		$sizeElt->setAttribute('size', '4');
		$sizeElt->setValue(1);
		$sizeElt->addValidators(array(
			tao_helpers_form_FormFactory::getValidator('NotEmpty'),
			tao_helpers_form_FormFactory::getValidator('Integer', array('min' => 1))
		));
		$this->form->addElement($sizeElt);
    }
1351267
public function addElement($element, $title = null, $name = null, $attrs = null) {
		if (! $element instanceof Element &&
			! $element instanceof Divider) {
			
			if ($element === self::DIVIDER) {
				$element = new Divider(null, $attrs);
			} else {
				if ($title === null) {
					$title = $element;
				}
				
				$element = new Element($element, $title, $attrs);
			}
		}
		
		if ($name === null && $title !== null) {
			$name = $title;
		}
		
		return parent::addElement($element, $name);
	}
1150739
protected function addFormElements(\Zend_Form $form)
    {
        if (! $this->user->hasTwoFactor()) {
            return;
        }

        $this->saveLabel = $this->_('Check code');

        $options = [
            'label'       => $this->_('Enter authenticator code'),
            'description' => $this->_('From the Google app on your phone.'),
            'maxlength'   => 6,
            'minlength'   => 6,
            'required'    => true,
            'size'        => 8,
            ];

        $element = $form->createElement('Text', 'TwoFactor', $options);
        $element->addValidator(new TwoFactorAuthenticateValidator(
                $this->user->getTwoFactorAuthenticator(),
                $this->user->getTwoFactorKey(),
                $this->translate
                ));

        $form->addElement($element);
    }
1117391
function() {
            var alreadyHasSelectAll = this.hasSelectAll();

            if (!alreadyHasSelectAll && this.options.includeSelectAllOption && this.options.multiple
                    && $('option', this.$select).length > this.options.includeSelectAllIfMoreThan) {

                // Check whether to add a divider after the select all.
                if (this.options.includeSelectAllDivider) {
                    this.$ul.prepend($(this.options.templates.divider));
                }

                var $li = $(this.options.templates.li);
                $('label', $li).addClass("checkbox");
                $('label', $li).append('<input type="checkbox" name="' + this.options.checkboxName + '" />');

                var $checkbox = $('input', $li);
                $checkbox.val(this.options.selectAllValue);

                $li.addClass("multiselect-item multiselect-all");
                $checkbox.parent().parent()
                    .addClass('multiselect-all');

                $('label', $li).append(" " + this.options.selectAllText);

                this.$ul.prepend($li);

                $checkbox.prop('checked', false);
            }
        }
312574
protected function createComponentEditForm(): Form
	{
		$form = $this->formFactory->create();

		$form->addHidden('parent');

		$form->addCheckbox('isLink', 'webManager.web.pages.isLink')
			->setOption('id', 'page-isLink')
			->addCondition($form::EQUAL, false)
			->toggle('page-title')
			->toggle('page-keywords')
			->toggle('page-image')
			->toggle('page-background')
			->toggle('page-description')
			->toggle('page-content')
			->toggle('page-homePage');

		$homePage = $form->addCheckbox('homePage', 'webManager.web.pages.homePage')
			->setOption('id', 'page-homePage')
			->setDisabled(!$this->editHomePage);
		$homePage->addCondition($form::EQUAL, false)
			->toggle('page-name')
			->toggle('page-url')
			->toggle('page-views')
			->toggle('page-isLink');
		if ($homePage->isDisabled()) {
			$homePage->setOption('class', 'hidden');
		}

		$form->addText('name', 'webManager.web.pages.name')
			->setOption('id', 'page-name')
			->addConditionOn($form['homePage'], $form::EQUAL, false)
			->setRequired();

		$form->addText('url', 'default.url')
			->setOption('id', 'page-url')
			->addConditionOn($form['isLink'], $form::EQUAL, true)
			->setRequired();

		$form->addSelectUntranslated('locale', 'webManager.web.pages.locale')
			->setItems($this->localeService->allowed);

		$form->addCheckboxListUntranslated('views', 'webManager.web.pages.views.title')
			->setOption('id', 'page-views')
			->setItems($this->orm->pagesViews->fetchPairsById());

		$form->addText('title', 'webManager.web.pages.pageTitle')
			->setOption('id', 'page-title')
			->setRequired(false)
			->addRule(Form::MAX_LENGTH, null, 150);

		$form->addTextArea('keywords', 'webManager.web.pages.keywords')
			->setOption('id', 'page-keywords')
			->setRequired(false)
			->addRule(Form::MAX_LENGTH, null, 255);

		$form->addImageUpload('image', 'webManager.web.pages.photo', 'webManager.web.pages.photoDelete')
			->setNamespace('pages')
			->setPreview('300x100')
			->setOption('id', 'page-image');

		$form->addColor('background', 'webManager.web.pages.background')
			->setOption('id', 'page-background');

		$form->addTextArea('description', 'webManager.web.pages.description')
			->setOption('id', 'page-description')
			->setRequired(false)
			->addRule(Form::MAX_LENGTH, null, 255);

		$form->addTextEditor('content', 'webManager.web.pages.content')
			->setOption('id', 'page-content');

		$form->addSubmit('save', 'form.save');

		$form->addLink('back', 'form.back', $this->getBacklink());

		$form->onSuccess[] = [$this, 'editFormSucceeded'];

		return $form;
	}
1273279
protected function addFormElements(\Zend_Form $form)
    {
        $this->saveLabel = $this->_('Save Two Factor Setup');

        $this->authenticator->addSetupFormElements($form, $this->user, $this->formData);

        if ($this->user->canSaveTwoFactorKey()) {
            $options = [
                'label' => $this->_('Enabled'),
                ];

            $keyElement = $form->createElement('Checkbox', 'twoFactorEnabled', $options);
            $form->addElement($keyElement);
        }
    }
832077
protected function addElement_select ($name, $label, $customElementConfig=array())
    {
        $defaultElementConfig = array(
            'name'       => $name,
            'attributes' => array(
                'id'         => $name,
            ),
            'options'    => array(
                'label'      => $label,
            ),
        );
        $elementConfig = array_replace_recursive(
            $defaultElementConfig,
            $customElementConfig
        );

        $this->addElement_select_configArray($elementConfig);
    }
642090
protected function addCheckFields()
    {
        $check = 1;
        foreach ($this->checkFields as $label => &$value) {
            if ($value instanceof \Zend_Form_Element) {
                $element = $value;
            } else {
                if ($value) {
                    $element = new \Zend_Form_Element_Text('check_' . $check);
                    $element->setAllowEmpty(false);
                    $element->setLabel($label);

                    $validator = new \Zend_Validate_Identical($value);
                    $validator->setMessage(
                            sprintf($this->_('%s is not correct.'), $label),
                            \Zend_Validate_Identical::NOT_SAME
                            );
                    $element->addValidator($validator);

                    $value = $element;
                    $check++;
                } else {
                    // Nothing to check for
                    unset($this->checkFields[$label]);
                    continue;
                }
            }
            $this->addElement($element);
        }
    }
311658
protected function InitForm()
    {
        $this->htmlWrap = $this->LoadElement();
        $name = 'Html';
        $this->AddRichTextField($name, $this->htmlWrap->GetHtml());
        $this->AddCssClassField();
        $this->AddCssIDField();
        $this->AddSubmit();
    }
1318335
protected function addElement_submit ($value, $customElementConfig=array())
    {
        $defaultElementConfig = array(
            'attributes' => array(
                'value'      => $value,
            ),
        );
        $elementConfig = array_replace_recursive(
            $defaultElementConfig,
            $customElementConfig
        );

        $this->addElement_submit_configArray($elementConfig);
    }
1100545
public function addElement(FieldsetInterface &$form, $name, $data)
    {
        if ($data['type'] == 'fieldset') {
            $fieldset = new Fieldset(['name' => $name]);
            foreach ($data['elements'] as $key => $def) {
                $this->addElement($fieldset, $key, $def);
            }
            $form->add($fieldset);
        } else {
            if (array_key_exists($data['type'], static::$_elementAlias)) {
                $class = static::$_elementAlias[$data['type']];
            } else if (
                is_subclass_of($data['type'], 'Slick\Form\ElementInterface')
            ) {
                $class = $data['type'];
            } else {
                throw new Exception\UnknownElementException(
                    "'{$data['type']}' is not a known alias or an implementation of " .
                    "Slick\\Form\\ElementInterface interface"
                );
            }

            /** @var Element $element */
            $element = new $class(['name' => $name]);

            if (isset($data['input'])) {
                $element->input = InputFilterFactory::createInput(
                    $data['input'],
                    $element->getName()
                );
            }

            if (!empty($data['validate'])) {
                $this->addValidation($element, $data['validate']);
            }

            foreach (array_keys($this->_elementProperties) as $key) {
                if (isset($data[$key])) {
                    $element->$key = $data[$key];
                }
            }

            $form->add($element);
        }
    }
795372
public function AddForm() {
		$classes = ClassInfo::subclassesFor(self::$tree_class);
		array_shift($classes);

		foreach ($classes as $key => $class) {
			if (!singleton($class)->canCreate())
				unset($classes[$key]);
			$classes[$key] = FormField::name_to_label($class);
		}

		$fields = new FieldList(
			new HiddenField("ParentID"),
			new HiddenField("Locale", 'Locale', i18n::get_locale()),
			$type = new DropdownField("ProviderType", "", $classes)
		);
		$type->setAttribute('style', 'width:150px');

		$actions = new FieldList(
			FormAction::create("addprovider", _t('ExternalContent.CREATE', "Create"))
				->addExtraClass('ss-ui-action-constructive')->setAttribute('data-icon', 'accept')
				->setUseButtonTag(true)
		);

		$form = new Form($this, "AddForm", $fields, $actions);

		$form->addExtraClass('cms-edit-form ' . $this->BaseCSSClasses());
		$this->extend('updateEditForm', $form);

		return $form;
	}
561663
protected function InitForm()
    {
        $this->repeater = $this->LoadElement();
        $this->AddCssClassField();
        $this->AddCssIDField();
        $this->AddTemplateField();
        $this->AddSubmit();
    }