Archived
1
0
Fork 0
This repository has been archived on 2026-04-03. You can view files and clone it, but you cannot make any changes to it's state, such as pushing and creating new issues, pull requests or comments.
httpcb/app/library/Form.php

70 lines
1.6 KiB
PHP

<?php
namespace Httpcb;
use Phalcon\Forms\Form as FormBase,
Phalcon\Forms\Element as FormElement;
class Form extends FormBase
{
public function renderDecorated($name, $opt = [])
{
$options = [
'label-class' => '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(
'<label class="%s" for="%s">%s</label>',
$opt['label-class'], $ele->getName(), $ele->getLabel());
}
$xhtml .= '<div class="' . implode(' ', $opt['class']) . '">'
. $ele->render();
if (strlen($opt['message']) > 0) {
$xhtml .= '<span class="help-block">' . $opt['message'] . '</span>';
}
$xhtml .= '</div>';
return $xhtml;
}
}