Beispiel #1
0
 public function preamble($form)
 {
     if ($form->attr['action'] === false) {
         return;
     }
     $attr = FormUtils::serializeAttr($form->attr);
     echo "<form {$attr}>\n";
 }
Beispiel #2
0
 public function getContent(array $extra_attr = array(), array $label = array())
 {
     $attr = array_merge_recursive($extra_attr, $this->attr);
     if ($this->getContainer() instanceof FormGroup) {
         return "<label class=\"form-checkbox\" " . FormUtils::serializeAttr($label) . "><input " . $this->serializeAttr($attr) . " /> {$this->text}</label>";
     } else {
         return "<input " . $this->serializeAttr($attr) . " />";
     }
 }
 public function preamble($form)
 {
     if ($this->preambleWritten || $form->attr['action'] === false) {
         return;
     }
     $sattr = FormUtils::serializeAttr($form->attr);
     echo "<form {$sattr}>\n";
     $this->preambleWritten = true;
 }
Beispiel #4
0
 public function serializeOptions($selected)
 {
     return implode("\n", array_map(function ($cur) use($selected) {
         $attr = ['value' => $cur->value];
         if ($cur->value == $selected) {
             $attr['selected'] = true;
         }
         $sattr = FormUtils::serializeAttr($attr);
         $label = htmlspecialchars($cur->label);
         return "<option {$sattr}>{$label}</option>";
     }, $this->options));
 }
Beispiel #5
0
 public function renderField($field, $error)
 {
     $label = $field->getLabel();
     $content = $field->getContent();
     $hint = $field->getHint();
     $required = $field->attribute('required');
     $class = ['form-row'];
     if ($required) {
         $class[] = 'required';
     }
     $row_attr = FormUtils::serializeAttr(['class' => $class]);
     if ($field instanceof FormInput) {
         list($prefix, $suffix) = $field->getAddons();
         $have_addon = (bool) ($prefix || $suffix);
         if ($prefix) {
             $prefix = "<span class=\"form-prefix\">{$prefix}</span>";
         }
         if ($suffix) {
             $suffix = "<span class=\"form-suffix\">{$suffix}</span>";
         }
     } else {
         $have_addon = false;
     }
     echo "<div {$row_attr}>\n";
     if ($label !== false) {
         echo "<span class=\"form-label\">{$label}</span>\n";
     }
     if ($have_addon) {
         echo "<span class=\"form-field\"><span class=\"form-addon\">{$prefix}{$content}{$suffix}</span></span>\n";
     } else {
         if ($content !== false) {
             echo "<span class=\"form-field\">{$content}</span>\n";
         }
     }
     if ($error !== false) {
         echo "<span class=\"form-error\">{$error}</span>\n";
     }
     if ($hint !== false) {
         echo "<span class=\"form-hint\">{$hint}</span>\n";
     }
     echo '</div>';
 }
Beispiel #6
0
 protected function serializeAttr($data = null)
 {
     return FormUtils::serializeAttr($data ?: $this->attr, ['type', 'name', 'id']);
 }