/**
  * Inject HTML in the navigation element
  *
  * @param string $html The HTML string
  * @return \ValidFormBuilder\StaticText
  */
 public function addHtml($html)
 {
     $objString = new StaticText($html);
     $objString->setMeta("parent", $this, true);
     $this->__fields->addObject($objString);
     return $objString;
 }
 /**
  * Add an `option` to the `optgroup`
  *
  * @param string $label Option's label
  * @param string $value Option's value
  * @param boolean $selected Set this option as selected by default
  * @return \ValidFormBuilder\SelectOption
  */
 public function addField($label, $value, $selected = false, $meta = array())
 {
     $objOption = new SelectOption($label, $value, $selected, $meta);
     $objOption->setMeta("parent", $this, true);
     $this->__options->addObject($objOption);
     return $objOption;
 }
Example #3
0
 /**
  * Add either a radio button or checkbox to the group
  *
  * @param string $label The label
  * @param value $value The value
  * @param boolean $checked Set to true if this item should be checked / selected by default
  * @param array $meta The meta array
  *
  * @return \ValidFormBuilder\GroupField
  */
 public function addField($label, $value, $checked = false, $meta = array())
 {
     $name = $this->getName();
     $objField = new GroupField($this->getRandomId($name), $name, $this->__type, $label, $value, $checked, $meta);
     $objField->setMeta("parent", $this, true);
     $this->__fields->addObject($objField);
     // *** Set the default value if "checked" is set.
     if ($checked) {
         switch ($this->__type) {
             case ValidForm::VFORM_CHECK_LIST:
                 $arrDefault = is_array($this->__default) ? $this->__default : array($this->__default);
                 $arrDefault[] = $value;
                 $this->__default = $arrDefault;
                 break;
             default:
                 $this->__default = $value;
         }
     }
     return $objField;
 }
Example #4
0
 /**
  * Add a field object
  *
  * See {@link \ValidFormBuilder\Fieldset::addField()}
  *
  * @param \ValidFormBuilder\Base $objField
  */
 public function addField($objField)
 {
     if (get_class($objField) == "ValidFormBuilder\\Fieldset") {
         $objField->setMeta("parent", $this, true);
         $this->__elements->addObject($objField);
     } else {
         if ($this->__elements->count() == 0) {
             $objFieldset = new Fieldset();
             $this->__elements->addObject($objFieldset);
         }
         $objFieldset = $this->__elements->getLast();
         $objField->setMeta("parent", $objFieldset, true);
         $objFieldset->getFields()->addObject($objField);
         if ($objField->isDynamic() && get_class($objField) !== "ValidFormBuilder\\MultiField" && get_class($objField) !== "ValidFormBuilder\\Area") {
             $objHidden = new Hidden($objField->getId() . "_dynamic", ValidForm::VFORM_INTEGER, array("default" => 0, "dynamicCounter" => true));
             $objFieldset->addField($objHidden);
             $objField->setDynamicCounter($objHidden);
         }
     }
 }
Example #5
0
 /**
  * Add a multifield to the Area
  *
  * @param string $label The multifield's label
  * @param array $meta The standard meta array
  * @return \ValidFormBuilder\MultiField
  */
 public function addMultiField($label = null, $meta = array())
 {
     if (!array_key_exists("dynamic", $meta)) {
         $meta["dynamic"] = $this->__dynamic;
     }
     // *** Overwrite dynamic settings. We cannot have a dynamic multifield inside a dynamic area.
     if ($this->__dynamic) {
         $meta["dynamic"] = $this->__dynamic;
         $meta["dynamicLabel"] = "";
     }
     $objField = new MultiField($label, $meta);
     $objField->setRequiredStyle($this->__requiredstyle);
     $objField->setMeta("parent", $this, true);
     $this->__fields->addObject($objField);
     return $objField;
 }
Example #6
0
 /**
  * Add text to the multifield.
  *
  * Same as {@link \ValidFormBuilder\ValidForm::addText()}
  *
  * @param string $strText The text to add (can be HTML as well)
  * @param array $meta The meta array
  * @return \ValidFormBuilder\String
  */
 public function addText($strText, $meta = array())
 {
     $objString = new String($strText, $meta);
     $objString->setMeta("parent", $this, true);
     $this->__fields->addObject($objString);
     return $objString;
 }
Example #7
0
 /**
  * Add a fieldset to the form field collection
  *
  * Example:
  * ```php
  * $objForm->addFieldset("Header for fieldset", "Note", "Cool fields contained by fieldset.");
  * ```
  * @param string $header The header for this fieldset
  * @param string $noteHeader An optional header for the 'note' block on the side of this fieldset
  * @param string $noteBody The optional body for the 'note block on the side of this fieldset
  * @param array $meta The meta array
  *
  * @return \ValidFormBuilder\Fieldset
  */
 public function addFieldset($header = null, $noteHeader = null, $noteBody = null, $meta = array())
 {
     $objFieldSet = new Fieldset($header, $noteHeader, $noteBody, $meta);
     $this->__elements->addObject($objFieldSet);
     return $objFieldSet;
 }
 /**
  * Get a flat Collection of all internal elements.
  *
  * This loops through all elements and adds each element and their children to a new Collection which will be
  * returned. This results in a flat Collection filled with ValidForm Builder elements.
  *
  * @return \ValidFormBuilder\Collection
  */
 public function getFields()
 {
     $objFields = new Collection();
     foreach ($this->__elements as $objFieldset) {
         if ($objFieldset->hasFields()) {
             foreach ($objFieldset->getFields() as $objField) {
                 if (is_object($objField)) {
                     if ($objField->hasFields()) {
                         if (get_class($objField) == "ValidFormBuilder\\Area" && $objField->isActive()) {
                             $objFields->addObject($objField);
                         }
                         foreach ($objField->getFields() as $objSubField) {
                             if (is_object($objSubField)) {
                                 if ($objSubField->hasFields()) {
                                     if (get_class($objSubField) == "ValidFormBuilder\\Area" && $objSubField->isActive()) {
                                         $objFields->addObject($objSubField);
                                     }
                                     foreach ($objSubField->getFields() as $objSubSubField) {
                                         if (is_object($objSubSubField)) {
                                             $objFields->addObject($objSubSubField);
                                         }
                                     }
                                 } else {
                                     $objFields->addObject($objSubField);
                                 }
                             }
                         }
                     } else {
                         $objFields->addObject($objField);
                     }
                 }
             }
         } else {
             $objFields->addObject($objFieldset);
         }
     }
     $this->__cachedfields = $objFields;
     return $objFields;
 }
Example #9
0
 /**
  * Add optgroup element
  *
  * @param string $label The optgroup's label
  * @return \ValidFormBuilder\SelectGroup
  */
 public function addGroup($label)
 {
     $objGroup = new SelectGroup($label);
     $objGroup->setMeta("parent", $this, true);
     $this->__options->addObject($objGroup);
     return $objGroup;
 }