Example #1
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 #2
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;
 }