Пример #1
0
 /**
  * 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;
 }
Пример #2
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;
 }
Пример #3
0
 /**
  * Check if this area contains child objects.
  * @internal
  * @return boolean True if fields collection > 0, false if not.
  */
 public function hasFields()
 {
     return $this->__fields->count() > 0 ? true : false;
 }
Пример #4
0
 /**
  * Create a Multifield element
  *
  * Multifield elements allow you to combine multiple fields horizontally with one label.
  * For example, create a first name + last name field with label "Full name"
  *
  * ```php
  * $objMulti = $objForm->addMultifield("Full name");
  * // Note: when using addField on a multifield, we don't set a label!
  * $objMulti->addField(
  *     "first-name",
  *     ValidForm::VFORM_STRING,
  *     array(),
  *     array(),
  *     // Keep it short, this is just a first name field
  *     array("style" => "width: 50px")
  * );
  * $objMulti->addField("last-name", ValidForm::VFORM_STRING);
  * ```
  *
  * You can also combine select elements to create a date picker:
  *
  * ```php
  * $objMulti = $objForm->addMultiField("Birthdate");
  * $objMulti->addField(
  *     "year",
  *     ValidForm::VFORM_SELECT_LIST,
  *     array(),
  *     array(),
  *     array(
  *         "start" => 1920,
  *         "end" => 2014,
  *         // 'fieldstyle' gets applied on the <select>
  *         // regular 'style' applies on the wrapping <div>
  *         "fieldstyle" => "width: 75px"
  *     )
  * );
  * $objMulti->addField(
  *     "month",
  *     ValidForm::VFORM_SELECT_LIST,
  *     array(),
  *     array(),
  *     array(
  *         "start" => 01,
  *         "end" => 12,
  *         "fieldstyle" => "width: 75px"
  *     )
  * );
  * $objMulti->addField(
  *     "day",
  *     ValidForm::VFORM_SELECT_LIST,
  *     array(),
  *     array(),
  *     array(
  *         "start" => 1,
  *         "end" => 31,
  *         "fieldstyle" => "width: 75px"
  *     )
  * );
  * ```
  *
  * @param string $label
  * @param array $meta The meta array
  * @return \ValidFormBuilder\MultiField
  */
 public function addMultiField($label = null, $meta = array())
 {
     $objField = new MultiField($label, $meta);
     $objField->setRequiredStyle($this->__requiredstyle);
     // *** Fieldset already defined?
     $objFieldset = $this->__elements->getLast("ValidFormBuilder\\Fieldset");
     if ($this->__elements->count() == 0 || !is_object($objFieldset)) {
         $objFieldset = $this->addFieldset();
     }
     $objField->setMeta("parent", $objFieldset, true);
     // *** Add field to the fieldset.
     $objFieldset->addField($objField);
     return $objField;
 }
 /**
  * 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;
 }
Пример #6
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;
 }