diff --git a/app/library/Form.php b/app/library/Form.php new file mode 100644 index 0000000..ebbb8bc --- /dev/null +++ b/app/library/Form.php @@ -0,0 +1,70 @@ + 'control-label', + 'class' => [ 'col-sm-10' ], + 'message' => '' + ]; + + $ele = $this->get($name); + + if (isset($opt['label-length'])) { + $length = (int) $opt['label-length']; + } else { + $length = 2; + } + $options['label-class'] .= ' col-sm-' . $length; + + if (isset($opt['length'])) { + + $len = $opt['length']; + + if ($len === 'full') { + $options['class'] = []; + } else { + $options['class'] = [ 'col-sm-' . $len ]; + } + + unset($opt['length']); + } + + if ($ele->hasMessages()) { + $options['class'][] = 'has-error'; + $options['message'] = $ele->getMessages()->current(); + } + + return $this->_render($ele, $options); + } + + protected function _render(FormElement $ele, $opt) + { + $xhtml = ''; + + if (strlen($ele->getLabel()) > 0) { + + $xhtml .= sprintf( + '', + $opt['label-class'], $ele->getName(), $ele->getLabel()); + } + + $xhtml .= '