/**
  * Generates HTML output for the given MultiField object and its child elements
  *
  * @internal
  * @param MultiField $objField The Area object to parse
  * @param boolean $hideEmpty Set to true to hide empty field values from the overview. Defaults to false.
  * @param integer $intDynamicCount The dynamic counter for the current MultiField being parsed
  * @return string Generated HTML
  */
 private function multiFieldAsHtml($objField, $hideEmpty = false, $intDynamicCount = 0)
 {
     $strReturn = "";
     if ($objField->hasContent($intDynamicCount)) {
         if ($objField->hasFields()) {
             $strValue = "";
             $objSubFields = $objField->getFields();
             $intCount = 0;
             foreach ($objSubFields as $objSubField) {
                 $intCount++;
                 if (get_class($objSubField) == "ValidFormBuilder\\Hidden" && $objSubField->isDynamicCounter()) {
                     continue;
                 }
                 $varValue = $objSubField->getValue($intDynamicCount);
                 $strValue .= is_array($varValue) ? implode(", ", $varValue) : $varValue;
                 $strValue .= $objSubFields->count() > $intCount ? " " : "";
             }
             $strValue = trim($strValue);
             $strLabel = $objField->getShortLabel();
             if (!empty($strValue) && $hideEmpty || !$hideEmpty && !empty($strValue)) {
                 $strValue = nl2br($strValue);
                 $strValue = htmlspecialchars($strValue, ENT_QUOTES);
                 $strReturn .= "<tr class=\"vf__field_value\">";
                 $strReturn .= "<td valign=\"top\"";
                 $strReturn .= " style=\"white-space:nowrap; padding-right: 20px\"";
                 $strReturn .= " class=\"vf__field\">";
                 $strReturn .= $strLabel;
                 $strReturn .= "</td>";
                 $strReturn .= "<td valign=\"top\" class=\"vf__value\">";
                 $strReturn .= "<strong>" . $strValue . "</strong>";
                 $strReturn .= "</td>\n";
                 $strReturn .= "</tr>";
             }
         }
     }
     return $strReturn;
 }
Esempio n. 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;
 }