/** * Render a form <input> element from the provided $element * * @param ElementInterface $element Zend Form Element * * @throws Exception\InvalidArgumentException * @throws Exception\DomainException * @return string */ public function render(ElementInterface $element) { if (!$element instanceof CheckboxElement) { throw new Exception\InvalidArgumentException(sprintf('%s requires that the element is of type Zend\\Form\\Element\\Checkbox', __METHOD__)); } $name = $element->getName(); if (empty($name) && $name !== 0) { throw new Exception\DomainException(sprintf('%s requires that the element has an assigned name; none discovered', __METHOD__)); } $attributes = $element->getAttributes(); $attributes['name'] = $name; $attributes['type'] = $this->getInputType(); $attributes['value'] = $element->getCheckedValue(); $closingBracket = $this->getInlineClosingBracket(); if ($element->isChecked()) { $attributes['checked'] = 'checked'; } if ($element->getAttribute('class') != 'input-checkbox') { $rendered = sprintf('<input %s%s', $this->createAttributesString($attributes), $closingBracket); } else { if ($element->getAttribute('id') == '') { $element->setAttribute('id', 'checkbox-' . uniqid()); } unset($attributes['class']); $rendered = sprintf('<span class="input-checkbox"><input %s%s<label for="%s"></label></span>', $this->createAttributesString($attributes), $closingBracket, $element->getAttribute('id')); } return $rendered; }
public function render(ElementInterface $element) { /* just a reminder. the types are: checkbox, color, date, datetime, datetime-local, email, file, hidden image, month, multi_checkbox, number, password, radio, range, reset search, select, submit, tel, text, textarea, time, url, week */ $labelHelper = $this->getLabelHelper(); $escapeHelper = $this->getEscapeHtmlHelper(); $elementHelper = $this->getElementHelper(); $elementErrorHelper = $this->getElementErrorHelper(); $descriptionHelper = $this->getDescriptionHelper(); $groupWrapper = $groupWrapper ?: $this->groupWrapper; $controlWrapper = $controlWrapper ?: $this->controlWrapper; $id = $element->getAttribute('id') ?: $element->getAttribute('name'); $html = ""; $label = $element->getAttribute('label'); if ($label) { $html .= $labelHelper->openTag(array('for' => $id, 'class' => 'control-label')); // todo allow for not escaping the label $html .= $escapeHelper($label); $html .= $labelHelper->closeTag(); } $html .= sprintf($controlWrapper, $id, $elementHelper->render($element), $descriptionHelper->render($element), $elementErrorHelper->render($element)); $addtClass = $element->getMessages() ? ' error' : ''; echo $element->getLabel(); die; $output .= parent::render($element); return $output; }
/** * Return a closing label tag * * @return string */ public function closeTag() { $result = '</label>'; if ($this->element->hasAttribute('required') && $this->element->getAttribute('required')) { $result = sprintf('<span class="required-mark">*</span> %s', $result); } return $result; }
/** * @param ElementInterface $element * * @return string */ public function render(ElementInterface $element) { $captcha = $element->getCaptcha(); if ($captcha === null || !$captcha instanceof AdapterInterface) { throw new Exception\DomainException(sprintf('%s requires that the element has a "captcha" attribute implementing Zend\\Captcha\\AdapterInterface', __METHOD__)); } $name = $element->getName(); $id = $element->getAttribute('id') ? $element->getAttribute('id') : $name; $captchaPattern = '<div %s></div>'; $captchaAttributes = $this->createAttributesString(array('class' => 'g-recaptcha ' . $element->getAttribute('class'), 'data-sitekey' => $captcha->getSiteKey(), 'data-theme' => $captcha->getTheme(), 'data-type' => $captcha->getType(), 'data-callback' => $captcha->getCallback())); $captchaElement = sprintf($captchaPattern, $captchaAttributes); $input = $this->renderHiddenInput($id, $name); $js = $this->renderJsCallback($captcha->getCallback(), $id); return $captchaElement . $input . $js; }
public function render(ElementInterface $element) { if (in_array($element->getAttribute('type'), array('html'))) { return $element->getValue(); } return parent::render($element); }
public function render(ElementInterface $element) { $element->setAttribute('class', $element->getAttribute('class') . " btn"); $input = parent::render($element); $options = $element->getOptions(); if (!empty($options['as-group'])) { $col_left_width = 'sm-6'; $col_right_width = 'sm-6'; $button_column = 'left'; if (!empty($options['col-left-width'])) { $col_left_width = $options['col-left-width']; } if (!empty($options['col-right-width'])) { $col_right_width = $options['col-right-width']; } if (!empty($options['button-column'])) { $button_column = $options['button-column']; } $colFormat = '<div class="col-%s">%s</div><div class="col-%s">%s</div>'; $buttonFormat = '<div class="btn-group btn-group-justified"><div class="btn-group">%s</div></div>'; $inputContainer = sprintf($buttonFormat, $input); $leftColumn = $inputContainer; $rightColumn = ''; if ($button_column != 'left') { $leftColumn = ''; $rightColumn = $inputContainer; } $input = sprintf($colFormat, $col_left_width, $leftColumn, $col_right_width, $rightColumn); } return $input; }
public function render(ElementInterface $element = null) { if ($element->getMessages()) { $element->setAttribute('class', 'error ' . $element->getAttribute('class')); } return parent::render($element); }
public function init(ElementInterface $element) { $this->formElement = $element; if ($element->hasAttribute('template')) { $this->template = $element->getAttribute('template'); } }
/** * Override * * Render the captcha * * @param ElementInterface $element * @throws Exception\DomainException * @return string */ public function render(ElementInterface $element) { //we could also set the separator here to break between the inputs and the image. //$this->setSeparator('') $captcha = $element->getCaptcha(); if ($captcha === null || !$captcha instanceof CaptchaAdapter) { throw new DomainException(sprintf('%s requires that the element has a "captcha" attribute of type Recruitment\\Model\\CaptchaImage; none found', __METHOD__)); } $captcha->generate(); $imgAttributes = array('width' => $captcha->getWidth(), 'height' => $captcha->getHeight(), 'alt' => $captcha->getImgAlt(), 'src' => $captcha->getImgUrl() . $captcha->getId() . $captcha->getSuffix(), 'class' => 'thumbnail center-block'); if ($element->hasAttribute('id')) { $imgAttributes['id'] = $element->getAttribute('id') . '-image'; } $closingBracket = $this->getInlineClosingBracket(); $img = sprintf('<img %s%s ', $this->createAttributesString($imgAttributes), $closingBracket); $position = $this->getCaptchaPosition(); $separator = $this->getSeparator(); $captchaInput = $this->renderCaptchaInputs($element); $pattern = '%s' . '<div class="input-group">' . '%s%s' . '<span class="input-group-btn">' . '<button id="' . $element->getAttribute('id') . '-refresh' . '" class="btn btn-default" type="button">' . '<i class="ion-loop"></i>' . '</button>' . '</span>' . '</div>'; if ($position == self::CAPTCHA_PREPEND) { return sprintf($pattern, $captchaInput, $separator, $img); } return sprintf($pattern, $img, $separator, $captchaInput); }
/** * {@inheritDoc} */ public function render(ElementInterface $element) { $captcha = $element->getCaptcha(); if ($captcha === null || !$captcha instanceof CaptchaAdapter) { throw new Exception\DomainException(sprintf('%s requires that the element has a "captcha" attribute' . ' of type Zend\\Captcha\\Image; none found', __METHOD__)); } // Generates ID, but NOT word and image $captcha->generate(); // Generates URL to access image, and image won't be generated until the URL is accessed $imgSrc = $captcha->getImgUrl() . '?id=' . $captcha->getId(); $imgAttributes = array('width' => $captcha->getWidth(), 'height' => $captcha->getHeight(), 'src' => $imgSrc, 'onclick' => sprintf('this.src=\'%s&refresh=\'+Math.random()', $imgSrc), 'style' => 'cursor: pointer; vertical-align: middle;', 'alt' => __('CAPTCHA image'), 'title' => __('Click to refresh CAPTCHA')); if ($element->hasAttribute('id')) { $imgAttributes['id'] = $element->getAttribute('id') . '-image'; } else { $imgAttributes['id'] = $captcha->getId() . '-image'; } $closingBracket = $this->getInlineClosingBracket(); $img = sprintf('<img %s%s', $this->createAttributesString($imgAttributes), $closingBracket); $position = $this->getCaptchaPosition(); $separator = $this->getSeparator(); $captchaInput = $this->renderCaptchaInputs($element); $pattern = '%s%s%s'; if ($position == static::CAPTCHA_PREPEND) { return sprintf($pattern, $captchaInput, $separator, $img); } return sprintf($pattern, $img, $separator, $captchaInput); }
/** * Render a form <input> element from the provided $element * * @param ElementInterface $element * @throws Exception\DomainException * @return string */ public function render(ElementInterface $element) { $src = $element->getAttribute('src'); if (empty($src)) { throw new Exception\DomainException(sprintf('%s requires that the element has an assigned src; none discovered', __METHOD__)); } return parent::render($element); }
public function render(ElementInterface $element) { if ($element->hasAttribute('data-placeholder')) { $placeholder = $element->getAttribute('data-placeholder'); $placeholder = $this->getTranslator()->translate($placeholder, $this->getTranslatorTextDomain()); $element->setAttribute('data-placeholder', $placeholder); } return parent::render($element); }
/** * Render a form <input> element from the provided $element * * @param ElementInterface $element * @throws Exception\DomainException * @return string */ public function render(ElementInterface $element) { $class = $element->getAttribute('class'); if (in_array($this->getType($element), array('submit', 'reset', 'button'))) { $class = 'btn' . (empty($class) ? '' : ' ' . $class); } $element->setAttribute('class', $class); return parent::render($element); }
/** * Prepares the element prior to rendering * @param \Zend\Form\ElementInterface $element * @param string $formType * @param array $displayOptions * @return void */ protected function prepareElementBeforeRendering(ElementInterface $element, $formType, array $displayOptions) { if (array_key_exists('class', $displayOptions)) { $class = $element->getAttribute('class'); $class = $this->genUtil->addWords($displayOptions['class'], $class); $escapeHtmlAttrHelper = $this->getEscapeHtmlAttrHelper(); $class = $this->genUtil->escapeWords($class, $escapeHtmlAttrHelper); $element->setAttribute('class', $class); } $this->formUtil->addIdAttributeIfMissing($element); }
public function addScripts(ElementInterface $oElement) { $view = $this->getView(); $id = $oElement->getAttribute('id'); $inlinejs = sprintf(self::$inlineSriptFormat, $id); $script = $view->inlineScript(); $headScript = $view->headScript(); $script->appendScript($inlinejs, 'text/javascript', array('noescape' => true)); // Disable CDATA comments $headScript->appendFile($view->basePath('js/bootstrap-slider.min.js')); }
/** * @param ElementInterface $element * * @return \SxBootstrap\View\Helper\Bootstrap\Form\Input */ protected function initFormElement(ElementInterface $element) { $this->name($element->getName())->type('text'); $this->getElement()->addAttributes($element->getAttributes()); $type = $element->getAttribute('type'); if (null !== $type) { $this->type(strtolower($type)); } $this->value($element->getValue()); return $this; }
/** * Determine input type to use * * @param ElementInterface $element * @return string */ protected function getType(ElementInterface $element) { $type = $element->getAttribute('type'); if (empty($type)) { return 'text'; } $type = strtolower($type); if (!isset($this->validTypes[$type])) { return 'text'; } return $type; }
/** * Render a form <textarea> element from the provided $element * * @param ElementInterface $element * @return string */ public function render(ElementInterface $element) { $name = $element->getName(); if (empty($name)) { throw new Exception\DomainException(sprintf('%s requires that the element has an assigned name; none discovered', __METHOD__)); } $attributes = $element->getAttributes(); $attributes['name'] = $name; $content = (string) $element->getAttribute('value'); $escapeHtml = $this->getEscapeHtmlHelper(); return sprintf('<textarea %s>%s</textarea>', $this->createAttributesString($attributes), $escapeHtml($content)); }
/** * Renders a disabe form elements toggle checkboxes element. */ public function render(ElementInterface $element) { /* @var $element DisableElementsCapableFormSettings * @var $renderer \Zend\View\Renderer\PhpRenderer * @var $headscript \Zend\View\Helper\HeadScript * @var $basepath \Zend\View\Helper\BasePath */ $renderer = $this->getView(); $headscript = $renderer->plugin('headscript'); $basepath = $renderer->plugin('basepath'); $headscript->appendFile($basepath('Settings/js/forms.decfs.js')); return '<ul class="disable-elements-list" id="' . $element->getAttribute('id') . '-list"' . '>' . $this->renderCheckboxes($element->getCheckboxes()) . '</ul>'; }
/** * Render an element * * @param ElementInterface $oElement * @return string */ public function render(ElementInterface $oElement) { // Add form-controll class $sElementType = $oElement->getAttribute('type'); if (!in_array($sElementType, $this->options->getIgnoredViewHelpers()) && !$oElement instanceof Collection) { $sElementClass = $oElement->getAttribute('class'); if ($sElementClass) { if (!preg_match('/(\\s|^)form-control(\\s|$)/', $sElementClass)) { $oElement->setAttribute('class', trim($sElementClass . ' form-control')); } } else { $oElement->setAttribute('class', 'form-control'); } } $sMarkup = parent::render($oElement); // Addon prepend $aAddOnPrepend = $oElement->getOption('add-on-prepend'); if ($aAddOnPrepend) { $sMarkup = $this->renderAddOn($aAddOnPrepend) . $sMarkup; } // Addon append $aAddOnAppend = $oElement->getOption('add-on-append'); if ($aAddOnAppend) { $sMarkup .= $this->renderAddOn($aAddOnAppend); } if ($aAddOnAppend || $aAddOnPrepend) { $sSpecialClass = ''; // Input size $sElementClass = $oElement->getAttribute('class'); if ($sElementClass) { if (preg_match('/(\\s|^)input-lg(\\s|$)/', $sElementClass)) { $sSpecialClass .= ' input-group-lg'; } elseif (preg_match('/(\\s|^)input-sm(\\s|$)/', $sElementClass)) { $sSpecialClass .= ' input-group-sm'; } } return sprintf(self::$inputGroupFormat, trim($sSpecialClass), $sMarkup); } return $sMarkup; }
public function __invoke(ElementInterface $element = null, $labelContent = null, $position = null) { $labelContent = $element->getLabel(); // Implement all default lines of Zend\Form\View\Helper\FormLabel // Set $required to a default of true | existing elements required-value $required = $element->hasAttribute('required') ? $element->getAttribute('required') : true; if (true === $required && ($labelContent != '' || $labelContent != null || $labelContent != false)) { $labelContent = sprintf('<div class="col-lg-10"><span class="im-required">(*)</span> %s</div>', $labelContent); } elseif (false === $required && ($labelContent != '' || $labelContent != null || $labelContent != false)) { $labelContent = $labelContent; } return $labelContent; }
/** * @inheritdoc */ public function render(ElementInterface $element, $labelPosition = null) { $wrapper = '<div class="col-md-12">%s</div>'; if ($element->getAttribute('type') == 'multi_checkbox') { $wrapper = '<div class="col-md-2">%s</div>'; if ($this->count == 6) { $wrapper .= ' <div class="clearfix visible-lg-block"></div>'; $this->count = 0; } $this->count = $this->count + 1; } return sprintf($wrapper, parent::render($element)); }
/** * Render * * @param ElementInterface $elmenet * @param string $blockWrapper * @param string $inlineWrapper * @return string */ public function render(ElementInterface $element, $blockWrapper = null, $inlineWrapper = null) { $blockWrapper = $blockWrapper ?: $this->blockWrapper; $inlineWrapper = $inlineWrapper ?: $this->inlineWrapper; $html = ''; if ($inline = $element->getAttribute('help-inline')) { $html .= sprintf($inlineWrapper, $inline); } if ($block = $element->getAttribute('help-block')) { $html .= sprintf($blockWrapper, $block); } return $html; }
/** * Prepares the element prior to rendering * @param \Zend\Form\ElementInterface $element * @param string $formType * @param array $displayOptions * @return void */ protected function prepareElementBeforeRendering(ElementInterface $element, $formType, array $displayOptions) { $class = $element->getAttribute('class'); $class = $this->genUtil->addWords('btn', $class); if (array_key_exists('class', $displayOptions)) { $class = $this->genUtil->addWords($displayOptions['class'], $class); } if ($element->getOption('primary') && $element->getOption('primary') == true) { $class = $this->genUtil->addWords('btn-primary', $class); } $class = $this->genUtil->escapeWords($class, $this->getEscapeHtmlAttrHelper()); $element->setAttribute('class', $class); }
/** * Utility form helper that renders a label (if it exists), an element and errors * * @param ElementInterface $element * @throws \Zend\Form\Exception\DomainException * @return string */ public function render(ElementInterface $element, $labelPosition = null) { $escapeHtmlHelper = $this->getEscapeHtmlHelper(); $elementHelper = $this->getElementHelper(); $elementErrorsHelper = $this->getElementErrorsHelper(); $label = $element->getLabel(); $inputErrorClass = $this->getInputErrorClass(); if (isset($label) && '' !== $label) { // Translate the label if (null !== ($translator = $this->getTranslator())) { $label = $translator->translate($label, $this->getTranslatorTextDomain()); } } // Does this element have errors ? if (count($element->getMessages()) > 0 && !empty($inputErrorClass)) { $classAttributes = $element->hasAttribute('class') ? $element->getAttribute('class') . ' ' : ''; $classAttributes = $classAttributes . $inputErrorClass; $element->setAttribute('class', $classAttributes); } if ($this->partial) { $vars = array('element' => $element, 'label' => $label, 'labelAttributes' => $this->labelAttributes, 'labelPosition' => $this->labelPosition, 'renderErrors' => $this->renderErrors); return $this->view->render($this->partial, $vars); } $rowOpen = '<div class="form-group">'; $rowClose = '</div>'; $elementString = $elementHelper->render($element); if ($elementErrorsHelper->render($element)) { $rowOpen = '<div class="form-group has-error">'; $elementErrors = $elementErrorsHelper->setMessageOpenFormat('<p class="text-danger">')->setMessageSeparatorString('<br />')->setMessageCloseString('</p>')->render($element); $elementString .= $elementErrors; } // hidden elements do not need a <label> -https://github.com/zendframework/zf2/issues/5607 $type = $element->getAttribute('type'); if (isset($label) && '' !== $label && $type !== 'hidden') { if (!$element instanceof LabelAwareInterface || !$element->getLabelOption('disable_html_escape')) { $label = $escapeHtmlHelper($label); } if ($label !== '' && !$element->hasAttribute('id') || $element instanceof LabelAwareInterface && $element->getLabelOption('always_wrap')) { $label = '<label class="col-sm-3 control-label">' . $label . '</label>'; } $elementString = '<div class="col-sm-9">' . $elementString . '</div>'; // Button element is a special case, because label is always rendered inside it if ($element instanceof Button || $element instanceof Checkbox || $element instanceof Radio) { $label = '<div class="col-sm-3"></div>'; } $markup = $label . $elementString; } else { $markup = $elementString; } return $rowOpen . $markup . $rowClose; }
/** * Render a description from the provided $element * @param ElementInterface $element * @return string */ public function render(ElementInterface $element) { $type = $element->getAttribute('type'); if (!in_array($type, $this->supportedTypes)) { return ''; } $escapeHelper = $this->getEscapeHtmlHelper(); $html = ''; //Description if ($element->getOption('description')) { $html = '<p class="help-block">' . $escapeHelper($element->getOption('description')) . '</p>'; } return $html; }
/** * Utility form helper that renders a description * * @param ElementInterface $element * @param array $attributes * @return string */ public function render(ElementInterface $element, array $attributes = array()) { $message = $element->getAttribute('description'); if (!$message) { return ''; } // Prepare attributes for opening tag $attributes = array_merge($this->attributes, $attributes); $attributes = $this->createAttributesString($attributes); if (!empty($attributes)) { $attributes = ' ' . $attributes; } return $this->openTag($attributes) . $message . $this->closeTag(); }
/** * Renders the form row as a bootstrap form row * * @param ElementInterface $element * @param null $labelPosition * @return string */ public function render(ElementInterface $element, $labelPosition = null) { if ($element->getAttribute('type') != 'submit') { $elementAttributes = $element->getAttributes(); if (isset($elementAttributes['class']) && $elementAttributes['class'] != null) { $elementAttributes['class'] .= ' form-control'; } else { $elementAttributes['class'] = 'form-control'; } $element->setAttributes($elementAttributes); } $row = parent::render($element, $labelPosition); return '<div class="form-group">' . $row . '</div>'; }
/** * * @see FormRow::render() * @param ElementInterface $oElement * @return string */ public function render(ElementInterface $oElement, $labelPosition = null) { $sElementType = $oElement->getAttribute('type'); // Nothing to do for hidden elements which have no messages if ($sElementType === 'hidden' && !$oElement->getMessages()) { return parent::render($oElement); } // Retrieve expected layout $sLayout = $oElement->getOption('layout'); // Partial rendering if ($this->partial) { return $this->view->render($this->partial, array('element' => $oElement, 'label' => $this->renderLabel($oElement), 'labelAttributes' => $this->labelAttributes, 'labelPosition' => $this->labelPosition, 'renderErrors' => $this->renderErrors)); } $sRowClass = ''; if (($fgs = $oElement->getOption('form-group-size')) != false) { $sRowClass = $fgs; } // Validation state if (($sValidationState = $oElement->getOption('validation-state')) != false) { $sRowClass .= ' has-' . $sValidationState; } // "has-error" validation state case if ($oElement->getMessages()) { $sRowClass .= ' has-error'; // Element have errors if (($sInputErrorClass = $this->getInputErrorClass()) != false) { if (($sElementClass = $oElement->getAttribute('class')) != false) { if (!preg_match('/(\\s|^)' . preg_quote($sInputErrorClass, '/') . '(\\s|$)/', $sElementClass)) { $oElement->setAttribute('class', trim($sElementClass . ' ' . $sInputErrorClass)); } } else { $oElement->setAttribute('class', $sInputErrorClass); } } } // Column size if (($sColumSize = $oElement->getOption('column-size')) && $sLayout !== LeadFilterForm::LAYOUT_HORIZONTAL) { $sRowClass .= ' col-' . $sColumSize; } // Render element $sElementContent = $this->renderElement($oElement); // Render form row if ($sElementType === 'checkbox' && $sLayout !== LeadFilterForm::LAYOUT_HORIZONTAL) { return $sElementContent . PHP_EOL; } if (($sElementType === 'submit' || $sElementType === 'button' || $sElementType === 'reset') && $sLayout === LeadFilterForm::LAYOUT_INLINE) { return $sElementContent . PHP_EOL; } return sprintf(self::$formGroupFormat, $sRowClass, $sElementContent) . PHP_EOL; }
/** * Render element hint from the provided $element * @param ElementInterface $element * @return string */ public function render(ElementInterface $element) { $type = $element->getAttribute('type'); if (!in_array($type, $this->supportedTypes)) { return ''; } $escapeHelper = $this->getEscapeHtmlHelper(); $html = ''; //Hint if ($element->getOption('hint')) { $html = '<span class="help-inline">' . $escapeHelper($element->getOption('hint')) . '</span>'; } return $html; }