作者:rumea
项目:zf-twitter-bootstra
/**
* Generate an opening form tag
*
* @param null|FormInterface $form
* @return string
*/
public function openTag(FormInterface $form = null)
{
$attributes = array('action' => '', 'method' => 'get');
if ($form instanceof FormInterface) {
$formAttributes = $form->getAttributes();
if (array_key_exists('class', $formAttributes) && !empty($formAttributes['class'])) {
$formAttributes['class'] = $formAttributes['class'] . ' ';
} else {
$formAttributes['class'] = '';
}
switch ($form->getFormLayout()) {
case FormInstance::FORM_LAYOUT_SEARCH:
$formAttributes['class'] .= 'form-search';
break;
case FormInstance::FORM_LAYOUT_INLINE:
$formAttributes['class'] .= 'form-inline';
break;
case FormInstance::FORM_LAYOUT_HORIZONTAL:
default:
$formAttributes['class'] .= 'form-horizontal';
break;
}
if (!array_key_exists('id', $formAttributes) && array_key_exists('name', $formAttributes)) {
$formAttributes['id'] = $formAttributes['name'];
}
$attributes = array_merge($attributes, $formAttributes);
}
$tag = sprintf('<form %s>', $this->createAttributesString($attributes));
return $tag;
}
作者:bitrecruite
项目:CrossApplicantManage
public function prepareElement(FormInterface $form)
{
$form->setAttribute('class', ($this->isMultiple() ? 'multi' : 'single') . '-file-upload');
$form->setAttribute('data-is-empty', null === $this->getValue());
$this->form = $form;
parent::prepareElement($form);
}
作者:zourc
项目:zourc
public function renderAdditional(FormInterface $form, $type)
{
$result = '';
foreach ($this->contactTypes[$type] as $fieldName => $fieldOptions) {
$result .= $this->renderElement($form->get($fieldName), $fieldOptions, true);
}
return $result;
}
作者:juic3pow3r
项目:LdcUserProfil
public function validate(FormInterface $form, array $data)
{
$argv = compact('form', 'data');
$this->getEventManager()->trigger(__METHOD__ . '.pre', $this, $argv);
$form->setData($data);
$isValid = $form->isValid();
$this->getEventManager()->trigger(__METHOD__ . '.post', $this, $argv + array('success' => $isValid));
return $isValid;
}
作者:bitrecruite
项目:CrossApplicantManage
/**
* Render a form from the provided $form,
*
* @param FormInterface $form
* @param string $layout
* @param array $parameter
* @return string
*/
public function renderBare(FormInterface $form, $layout = self::LAYOUT_INLINE, $parameter = array())
{
$renderer = $this->getView();
$headscript = $renderer->plugin('headscript');
$basepath = $renderer->plugin('basepath');
$headscript->appendFile($basepath('Core/js/core.spinnerbutton.js'))->appendFile($basepath('js/select2.min.js'))->appendFile($basepath('Core/js/core.forms.js'));
$renderer->headLink()->appendStylesheet($basepath('css/select2.css'))->appendStylesheet($basepath('css/select2-bootstrap.css'));
if ($scripts = $form->getOption('headscript')) {
if (!is_array($scripts)) {
$scripts = array($scripts);
}
foreach ($scripts as $script) {
$headscript->appendFile($basepath($script));
}
}
$class = $form->getAttribute('class');
$class = preg_replace('~\\bform-[^ ]+\\b~', '', $class);
$class .= ' ' . $layout;
$form->setAttribute('class', $class);
if (method_exists($form, 'prepare')) {
$form->prepare();
}
$formContent = '';
if ($form instanceof ViewPartialProviderInterface) {
return $this->getView()->partial($form->getViewPartial(), array('element' => $form));
}
foreach ($form as $element) {
$parameterPartial = $parameter;
if (!$element->hasAttribute('id')) {
$elementId = preg_replace(array('~[^A-Za-z0-9_-]~', '~--+~', '~^-|-$~'), array('-', '-', ''), $form->getName() . '-' . $element->getName());
$element->setAttribute('id', $elementId);
}
if ($element instanceof ExplicitParameterProviderInterface) {
$parameterPartial = array_merge($element->getParams(), $parameterPartial);
}
if ($element instanceof ViewPartialProviderInterface) {
$parameterPartial = array_merge(array('element' => $element, 'layout' => $layout), $parameterPartial);
$formContent .= $this->getView()->partial($element->getViewPartial(), $parameterPartial);
} else {
if ($element instanceof ViewHelperProviderInterface) {
$helper = $element->getViewHelper();
if (is_string($helper)) {
$helper = $this->getView()->plugin($helper);
}
$formContent .= $helper($element);
} else {
if ($element instanceof FieldsetInterface) {
$formContent .= $this->getView()->formCollection($element, true, $layout);
} else {
$formContent .= $this->getView()->formRow($element, null, null, $layout);
}
}
}
}
return $this->openTag($form) . $formContent . $this->closeTag();
}
作者:coolm
项目:twb
/**
* @param string $content
* @param array $attribs
* @param ElementInterface $element
* @param FormInterface $form
* @return string
*/
public function render($content, array $attribs = [], ElementInterface $element = null, FormInterface $form = null)
{
if ($form && $form->hasAttribute('class')) {
$class = $form->getAttribute('class');
if (strpos($class, 'form-inline') !== false) {
return $content;
}
}
return parent::render($content, $attribs);
}
作者:acpl
项目:acplou
/**
* @param FormInterface|null $form
*/
private function setHorizontal($form)
{
if ($this->isHorizontal && $form !== null) {
if ($form->hasAttribute('class')) {
$form->setAttribute('class', 'form-horizontal ' . $form->getAttribute('class'));
} else {
$form->setAttribute('class', 'form-horizontal');
}
}
}
作者:fousheez
项目:for
public function handle(FormInterface $form, $options = array())
{
$options = array_merge($form->getOptions(), $options);
if (!isset($options[self::PARSED_FORM_OPTION_KEY])) {
$options[self::PARSED_FORM_OPTION_KEY] = new \FzyForm\Annotation\Form($form, $this->getServiceLocator()->get('FzyCommon\\Service\\EntityToForm'));
$form->setOptions($options);
}
/* @var $annotated \FzyForm\Annotation\Form */
$annotated = $options[self::PARSED_FORM_OPTION_KEY];
return $this->getServiceLocator()->get('FzyCommon\\Render')->handle($annotated->getTemplate(), array('element' => $annotated, 'options' => $options));
}
作者:till
项目:vufin
/**
* Generate an opening form tag
*
* @param null|FormInterface $form
* @return string
*/
public function openTag(FormInterface $form = null)
{
$attributes = array('action' => '', 'method' => 'get');
if ($form instanceof FormInterface) {
$formAttributes = $form->getAttributes();
if (!array_key_exists('id', $formAttributes) && array_key_exists('name', $formAttributes)) {
$formAttributes['id'] = $formAttributes['name'];
}
$attributes = array_merge($attributes, $formAttributes);
}
return sprintf('<form %s>', $this->createAttributesString($attributes));
}
作者:nebune
项目:zf2-twb-bundl
/**
* Sets form layout class
*
* @param FormInterface $oForm
* @param string $sFormLayout
* @return void
*/
protected function setFormClass(FormInterface $oForm, $sFormLayout = self::LAYOUT_HORIZONTAL)
{
if (is_string($sFormLayout)) {
$sLayoutClass = 'form-' . $sFormLayout;
if ($sFormClass = $oForm->getAttribute('class')) {
if (!preg_match('/(\\s|^)' . preg_quote($sLayoutClass, '/') . '(\\s|$)/', $sFormClass)) {
$oForm->setAttribute('class', trim($sFormClass . ' ' . $sLayoutClass));
}
} else {
$oForm->setAttribute('class', $sLayoutClass);
}
}
}
作者:andreas-serl
项目:athene
public function editPageRepository(FormInterface $form)
{
$page = $form->getObject();
if (!$form->isValid()) {
throw new RuntimeException(print_r($form->getMessages(), true));
}
$data = $form->getData(FormInterface::VALUES_AS_ARRAY);
$formClone = clone $form;
$formClone->bind($page);
$formClone->setData($data);
$formClone->isValid();
$this->assertGranted('page.update', $page);
$this->getObjectManager()->persist($page);
return $page;
}
作者:andreas-serl
项目:athene
public function createRole(FormInterface $form)
{
$this->assertGranted('authorization.role.create');
if (!$form->isValid()) {
throw new RuntimeException(print_r($form->getMessages(), true));
}
$processingForm = clone $form;
$data = $processingForm->getData(FormInterface::VALUES_AS_ARRAY);
$processingForm->bind(new Role());
$processingForm->setData($data);
if (!$processingForm->isValid()) {
throw new RuntimeException(print_r($processingForm->getMessages(), true));
}
$this->objectManager->persist($processingForm->getObject());
return $processingForm->getObject();
}
作者:camelcasetechs
项目:certigat
/**
* Render single element
*
* @access public
* @param FormInterface $form
* @param Zend\Form\Element $element
* @return string element HTML content
*/
public function renderElement($form, $element)
{
$inlineForm = false;
if (strpos($form->getAttribute('class'), "form-horizontal") === false) {
$inlineForm = true;
}
$elementContent = '';
// add required class to all required elements
if (!empty($element->getAttribute('required')) && !$element->getLabelOption("disable_html_escape")) {
$labelAttributes = $element->getLabelAttributes();
$labelClass = isset($labelAttributes["class"]) ? $labelAttributes["class"] : "";
$labelAttributes["class"] = $labelClass . " required";
$element->setLabelAttributes($labelAttributes);
}
// Add Id to all form elements
// When element has an Id, Label tag won't enclose form element
if (empty($element->getAttribute('id'))) {
$element->setAttribute('id', $form->getAttribute('name') . "_" . $element->getAttribute('name'));
}
$labelAbsent = false;
$formElementAppendString = '';
if (empty($element->getLabel()) && $element->getAttribute('type') !== "hidden") {
$labelAbsent = true;
}
if ($labelAbsent === true && (strpos($element->getAttribute('class'), "btn") === false || strpos($element->getAttribute('class'), "btn") !== false && strpos($element->getAttribute('class'), "pull") === false) && $inlineForm === false) {
$elementContent .= "<dt> </dt>";
} else {
$divAttributes = "";
if ($inlineForm === true) {
$divAttributes = "class='form-group'";
}
$elementContent .= "<div {$divAttributes} >";
$formElementAppendString = '</div>';
}
// Change submit button text to edit if form is an edit form
if ($element instanceof Submit && $form->isEditForm === true) {
if (property_exists($form, "isAdminUser") && $form->isAdminUser === false && $form->needAdminApproval === true) {
$element->setValue(FormButtons::SUBMIT_FOR_ADMIN_APPROVAL_BUTTON_TEXT);
} elseif ($element->getValue() == FormButtons::CREATE_BUTTON_TEXT) {
$element->setValue(FormButtons::EDIT_BUTTON_TEXT);
}
}
$elementContent .= $this->getView()->formRow($element);
$elementContent .= $formElementAppendString;
return $elementContent;
}
作者:cross-solutio
项目:yawi
public function render(FormInterface $form, $colMap = null, $buttonsSpan = null)
{
$headscript = $this->getView()->plugin('headscript');
$basepath = $this->getView()->plugin('basepath');
$headscript->appendFile($basepath('Core/js/core.searchform.js'));
if (is_int($colMap)) {
$buttonsSpan = $colMap;
$colMap = null;
}
if ($form instanceof ViewPartialProviderInterface) {
return $this->getView()->partial($form->getViewPartial(), ['element' => $form, 'colMap' => $colMap, 'buttonsSpan' => $buttonsSpan]);
}
$elements = $form->getElements();
$buttons = $form->getButtons();
$content = $this->renderElements($elements, $buttons, $colMap, $buttonsSpan);
return $this->openTag($form) . '<div class="row" style="padding: 0 15px;">' . $content . '</div>' . $this->closeTag();
}
作者:RalfEgger
项目:travello-view-helpe
/**
* Outputs message depending on flag
*
* @param FormInterface $form
* @param array $staticElements
* @param null $formClass
*
* @return string
*/
public function __invoke(FormInterface $form, array $staticElements = [], $formClass = null)
{
$submitElements = [];
/** @var Form $form */
$form->setAttribute('role', 'form');
if ($formClass == 'form-inline') {
$form->setAttribute('class', $formClass . ' pull-right');
} elseif ($formClass) {
$form->setAttribute('class', $formClass);
} else {
$formClass = $form->getAttribute('class');
}
$form->prepare();
$output = $this->getView()->form()->openTag($form);
foreach ($staticElements as $element) {
$viewModel = new ViewModel();
$viewModel->setVariable('label', $element['label']);
$viewModel->setVariable('value', $element['value']);
$viewModel->setTemplate('travello-view-helper/widget/bootstrap-form-static');
$output .= $this->getView()->render($viewModel);
}
list($output, $submitElements) = $this->renderElements($form, $formClass, $output, $submitElements);
if ($formClass == 'form-inline') {
$template = 'bootstrap-form-submit-inline';
} else {
$template = 'bootstrap-form-submit';
}
$viewModel = new ViewModel();
$viewModel->setVariable('submitElements', $submitElements);
$viewModel->setTemplate('travello-view-helper/widget/' . $template);
$output .= $this->getView()->render($viewModel);
$output .= $this->getView()->form()->closeTag();
return $output;
}
作者:Indigo133
项目:c4
public function updateAction()
{
$request = $this->getRequest();
$recipe = $this->readService->findById($this->params('id'));
if (false === $this->authorizationService->isGranted('recipe.manage', $recipe)) {
throw new UnauthorizedException('Insufficient Permissions');
}
$viewModel = new ViewModel();
$viewModel->setTemplate('recipe/update');
$viewModel->setVariables(['form' => $this->form]);
$this->form->bind($recipe);
if ($request->isPost()) {
$this->form->setData($request->getPost());
if ($this->form->isValid()) {
try {
$this->writeService->save($this->form->getData());
$this->flashMessenger()->addSuccessMessage('Rezept erfolgreich aktualisiert');
$this->redirect()->toRoute('recipe/read/update', ['id' => $this->params('id')]);
} catch (\Exception $e) {
var_dump($e->getMessage());
}
}
}
$this->layout('layout/backend');
return $viewModel;
}
作者:shitikovkiril
项目:LearnZF
public function indexAction()
{
$request = $this->getRequest();
$logContent = '';
// initialize when no submit anymore
$data = [];
$data['logmessage'] = $this->form->get('logmessage')->getValue();
if ($request->isPost()) {
$this->form->setData($request->getPost());
if ($this->form->isValid()) {
$data = $this->form->getData();
$this->loggerPriority = $data['logpriority'];
if ($data['logformat'] !== 'simple') {
$this->loggerConfig['writers'][0]['options']['formatter']['name'] = $data['logformat'];
unset($this->loggerConfig['writers'][0]['options']['formatter']['options']);
}
}
}
$logger = new Logger($this->loggerConfig);
// save log data to buffer and make it variable
ob_start();
$logger->log((int) $this->loggerPriority, $data['logmessage']);
$logContent = ob_get_clean();
return new ViewModel(['form' => $this->form, 'logContent' => $logContent]);
}
作者:zourc
项目:zourc
public function createAction()
{
if ($this->getRequest()->isPost()) {
$this->dashboardForm->setData($this->getRequest()->getPost());
if ($this->dashboardForm->isValid()) {
$data = $this->dashboardForm->getData();
$this->dashboardTaskService->persistFromArray($data);
return $this->redirect()->toRoute('dashboard/manage');
}
}
return new ViewModel(['dashboardForm' => $this->dashboardForm]);
}
作者:ughl
项目:ugh-authenticatio
/**
*
* @return ViewModel|Response
*/
public function indexAction()
{
if (!is_null($this->identity())) {
return $this->redirect()->toRoute($this->loginRedirectRoute);
}
if ($this->getRequest()->isPost()) {
$this->loginForm->setData($this->getRequest()->getPost());
if ($this->loginForm->isValid()) {
return $this->redirect()->toRoute($this->loginRedirectRoute);
}
}
return new ViewModel(array('loginForm' => $this->loginForm));
}
作者:shitikovkiril
项目:LearnZF
public function indexAction()
{
$request = $this->getRequest();
$formMessages = [];
$isPost = false;
if ($request->isPost()) {
$this->form->setData($request->getPost());
$this->form->isValid();
$formMessages = $this->form->getMessages();
$isPost = true;
}
return new ViewModel(['form' => $this->form, 'formMessages' => $formMessages, 'isPost' => $isPost]);
}