markocupic/contao-form-multirow-text-field-bundle
Composer 安装命令:
composer require markocupic/contao-form-multirow-text-field-bundle
包简介
Multirow frontend text field widget for Contao CMS
README 文档
README
Generate a multirow text field input within a contao frontend module controller using codefog/contao-haste form utils:
$objForm = new \Haste\Form\Form('pets_form', 'POST', function ($objHaste) { return $_POST['FORM_SUBMIT'] === $objHaste->getFormId(); }); $blnMandatory = false; $objForm->addFormField('pets', [ 'label' => $this->translator->trans('MSC.pets', [], 'contao_default'), 'inputType' => 'multirowText', 'eval' => ['mandatory' => $blnMandatory, 'multiple' => true], 'value' => $value, ]); $template->forms = $objForm->generate();
Example controller:
<?php declare(strict_types=1); /* * This file is part of Contao. * * (c) Leo Feyer * * @license LGPL-3.0-or-later */ namespace Markocupic\ContaoPetToMemberBundle\Controller\FrontendModule; use Contao\Controller; use Contao\CoreBundle\Controller\FrontendModule\AbstractFrontendModuleController; use Contao\Database; use Contao\MemberModel; use Contao\ModuleModel; use Contao\StringUtil; use Contao\Template; use Haste\Form\Form; use Haste\Util\Url; use Markocupic\ContaoFormMultirowTextFieldBundle\Forms\FormMultirowTextField; use Symfony\Component\HttpFoundation\Request; use Symfony\Component\HttpFoundation\Response; use Symfony\Contracts\Translation\TranslatorInterface; /** * Class AssignPetToMemberModuleController. */ class AssignPetToMemberModuleController extends AbstractFrontendModuleController { /** * @var TranslatorInterface */ private $translator; /** * AssignPetToMemberModuleController constructor. */ public function __construct(TranslatorInterface $translator) { $this->translator = $translator; } protected function getResponse(Template $template, ModuleModel $model, Request $request): ?Response { if ($request->query->has('id') && null !== ($objModel = MemberModel::findByPk($request->query->get('id')))) { // Prepare serialized string from multicolumn wizard field // to a default array => ['dog','cat','donkey'] $value = []; $arrValue = StringUtil::deserialize($objModel->pets, true); if (!empty($arrValue)) { $value = array_map( static function ($row) { return $row['species']; }, $arrValue ); } $objForm = new Form( 'pets_form', 'POST', static function ($objHaste) { return $_POST['FORM_SUBMIT'] === $objHaste->getFormId(); } ); $blnMandatory = false; $objForm->addFormField('pets', [ 'label' => $this->translator->trans('MSC.APTMMC-pets', [], 'contao_default'), 'inputType' => 'multirowText', 'eval' => ['mandatory' => $blnMandatory, 'multiple' => true], 'value' => $value, ]); // Let's add a submit button $objForm->addFormField('submit', [ 'label' => $this->translator->trans('MSC.APTMMC-submit', [], 'contao_default'), 'inputType' => 'submit', ]); $objForm->bindModel($objModel); // Save input if ($objForm->validate()) { /** @var FormMultirowTextField $objWidget */ $objWidget = $objForm->getWidget('pets'); // Remove empty values $objWidget->value = array_filter($objWidget->value); $blnError = false; // $objWidget->value will always be at least an empty array if (($blnMandatory && empty($objWidget->value)) || !\is_array($objWidget->value)) { $blnError = true; $objWidget->addError($this->translator->trans('ERR.APTMMC-fillInPetInput')); } if (!$blnError) { // Serialize input for storing in multicolumn wizard field $value = array_map( static function ($el) { return ['species' => $el]; }, $objWidget->value ); $objModel->pets = serialize($value); $objModel->save(); Controller::reload(); } } $template->user = $objModel; $template->form = $objForm->generate(); } // Member listing $objDb = Database::getInstance()->execute('SELECT * FROM tl_member'); $template->members = $objDb->fetchAllAssoc(); // Request $template->request = Url::removeQueryString(['id']); return $template->getResponse(); } }
markocupic/contao-form-multirow-text-field-bundle 适用场景与选型建议
markocupic/contao-form-multirow-text-field-bundle 是一款 基于 PHP 开发的 Composer 扩展包,目前已累计 99 次下载、GitHub Stars 达 0, 最近一次更新时间为 2020 年 09 月 28 日, 在 PHP 生态内属于活跃度较高的组件。
它主要适用于以下技术方向: 「bundle」 「contao」 「tag 1」 「tag 2」 等业务场景。在实际项目中,围绕这些方向常见需要落地的问题包括:接口对接、性能调优、并发安全、与既有框架(Laravel / ThinkPHP / Yii / Webman 等)的兼容适配,以及生产环境的日志埋点与稳定性保障。
我们在过去多个企业项目中使用过 markocupic/contao-form-multirow-text-field-bundle 或与其功能相近的方案,如果你在选型或落地过程中遇到问题,例如 版本兼容、二次改造、私有化封装、与内部系统对接、生产 BUG 排查,欢迎联系我们协助评估。
基于 markocupic/contao-form-multirow-text-field-bundle 在你已有业务上做功能扩展、字段裁剪、UI 适配、与内部账号 / 权限 / 日志系统的深度对接。
线上偶发问题、内存泄漏、慢查询、并发异常等排查修复;针对高流量场景做缓存、队列、索引层面的调优。
承接完整的项目从需求 → 设计 → 开发 → 上线 → 长期运维;也可按月提供技术保姆服务。
与 markocupic/contao-form-multirow-text-field-bundle 相关的其它包
同方向 / 同关键字的高下载量 PHP Composer 包推荐,方便对比选型:
Contao Open Source CMS
2lenet/EasyAdminPlusBundle
The bundle for easy using json-rpc api on your project
Diese Contao 4 Erweiterung stellt Google reCAPTCHA V2 in Form eines neuen Formularfeldes im Formulargenerator bereit. This extension provides Google reCAPTCHA V2 in the form of a new form field in the form generator of Contao Open Source CMS.
Provide a way to secure accesses to all routes of an symfony application.
DMS Meetup API Bundle, enables Meetup API clients in services
统计信息
- 总下载量: 99
- 月度下载量: 0
- 日度下载量: 0
- 收藏数: 0
- 点击次数: 13
- 依赖项目数: 0
- 推荐数: 0
其他信息
- 授权协议: MIT
- 更新时间: 2020-09-28
