定制 k1sul1/wp-libre-formbuilder 二次开发

按需修改功能、优化性能、对接业务系统,提供一站式技术支持

邮箱:yvsm@zunyunkeji.com | QQ:316430983 | 微信:yvsm316

k1sul1/wp-libre-formbuilder

Composer 安装命令:

composer require k1sul1/wp-libre-formbuilder

包简介

Formbuilder addon for WP Libre Form.

README 文档

README

This was a prototype which could've been a fully functional visual form builder. It was a bit too ambitiuous, and edge cases and the aholes at wp.org Plugin Review Team killed it.

If I were to start from the beginning, I'd build the components from React, and not HTML with hacks. Fields like select can get quite a bit more complex than just a few options. I might've forgotten the existence of optiongroup etc when building the prototype, and pretty much everything is based on the idea that you have elements which can take one children.

See limitations below if you're curious on why this isn't as easy as I thought it would be.

Screenshots

in move mode in preview mode in edit mode in field add screen

How does it work

Think of it as a preprocessor for WP Libre Form. It provides some built-in building blocks, and lets you create block from any* HTML. See Limitations.

All of the standard features should work just fine. Dynamic values? Check. Multilinguality support with Polylang? Check.

Terminology

It's easy to get confused on what word means what. Hopefully this will help.

  • field: The content field in wplfb-field post type. If using wplf()->plugins->Formbuilder->addField(), it matches the array element with the same key.
  • template: The field template textarea in wplfb-field post type. Same applies for PHP API. Used to provide wrapping HTML for the customizable input.

Limitations

Turns out that working with arbitrary HTML is pretty hard. Especially if it has to be user editable. The HTML spec doesn't make things any easier. Things like <textarea> accept a default input value as a child, in addition to supporting the value attribute. <button> doesn't accept the value attribute, and instead renders any HTML inside it.

These are the limitations at the moment. Some might be permanent, but most likely everything is fixable. It's just this limited amount of time, resources and motivation I have that limit my ability to fix said limitations.

Is something missing from this list? Add an issue or send a PR with it added.

Nested HTML tags inside field do not work

Example:

<div class="wrapper" doge="cate">
  <div class="test">
    <div class="wplfb-child-container"></div>
  </div>
</div>

div.test just magically disappears. Fixing this probably requires recursion and there's already plenty of it in the codebase. This will most likely be fixed in the future, if you've ideas on how, please contribute.

This is a real problem with things like <select> inputs.

Workaround: You tell me. Dynamic values feature of WPLF?

Only the first HTML tag is customizable inside field

Related to the previous limitation, but is also a design decision.

<div class="wrapper" doge="cate">
  <div class="wplfb-child-container"></div>
</div>

You can edit the class and doge attributes, but you have no control over the element with the class wplfb-child-container.

This will probably stay like this forever, for a couple of reasons

  1. It increases the cyclomatic complexity of the codebase by a fucking lot
  2. It's an UI nightmare
  3. It can be worked around

Making changes to fields don't sync to forms

This is pretty much a design decision. When you've added a field to a form, it will render the same way every time, even if you make changes to the underlying field object.

Example:

  1. Add wrapper field to form
  2. Edit wrapper field and add a new attribute to it
  3. Save the form

The wrapper field in the form will not contain the new attribute.

Possibly fixed in later versions by adding a sync button to forms or invidual fields.

This is to make sure that updates to this plugin can change the defaults and not break anything.

Workaround: Add a new field, select the same type, add the attributes, delete the old field.

How to add fields

The easy way

Using wp-admin: /wp-admin/post-new.php?post_type=wplfb-field

Follow the instructions in the Field metabox.

Using PHP

This assumes that you're running the latest version of WP Libre Form.

wplf()->plugins->Formbuilder->addField([
  'key' => 'U0', // Used to differentiate fields from others, especially when two fields share the same name
  'name' => 'Range', // Name shown to the end user
  'field' => '<input type="range" name="range" value="3" min="1" max="5">', // HTML fragment. Attributes will be editable.
  'template' => '<div class="wrapper-div"><div class="wplfb-field-container"></div></div>', // HTML fragment for wrapping field with
  'label' => 'On a scale of 1 to 5, how did we do?', // Default label for input, leave empty to disable
]);

Wrapper fields

Sometimes you want to nest fields, or group them in logical sections. Wrapper fields allow you to do just that. They're normal fields but they don't contain any inputs themselves, usually.

<div>
  <p>Elements before inputs</p>
  <div class="wplfb-child-container">
    <!-- Children can be put here! -->
  </div>
  <p>Elements after inputs</p>
</div>

The class wplfb-child-container is mandatory.

Templates

In addition to having wrapper fields, you can provide a template that wraps your field. Useful for adding boilerplate around the inputs allowing you to utilize the power of CSS frameworks like Bootstrap, Foundation, or Pure. Templates can't have configurable parameters. But you can probably use wrapper fields to achieve that and live.

<div>
  <h3>This is a very important heading</h3>

  <div class="wplfb-field-container">
    <!-- This element will be replaced with the input element! -->
  </div>
</div>

The class wplfb-field-container is mandatory.

Hold up. Templates and wrappers look like the same to me?

Indeed they do, but they're not. Templates can't contain multiple fields, as in, they can't have children. When you use templates, the tag you used for the template is discarded and a field takes it's place, but when you use wrapper fields, you can put any field inside it and the wrapping element is preserved.

FAQ

Why no drag & drop?

DnD interfaces are often tedious to use. Sure, they work great on desktop, when there's one level, but complex forms may have any number of levels. Using mobile devices with limited screen space makes it spectacularly easy to ruin everything misplace elements.

By not relying on DnD the code stays relatively simple, and works on every device. The current move controls should feel intuitive, and after adding keyboard shortcuts everything should be a breeze.

If there's demand, drag & drop controls might be implemented, there's nothing in the code preventing that from being done.

k1sul1/wp-libre-formbuilder 适用场景与选型建议

k1sul1/wp-libre-formbuilder 是一款 基于 PHP 开发的 Composer 扩展包,目前已累计 31 次下载、GitHub Stars 达 5, 最近一次更新时间为 2017 年 06 月 10 日, 在 PHP 生态内属于活跃度较高的组件。

我们在过去多个企业项目中使用过 k1sul1/wp-libre-formbuilder 或与其功能相近的方案,如果你在选型或落地过程中遇到问题,例如 版本兼容、二次改造、私有化封装、与内部系统对接、生产 BUG 排查,欢迎联系我们协助评估。

围绕 k1sul1/wp-libre-formbuilder 我们能提供哪些服务?
定制开发 / 二次开发

基于 k1sul1/wp-libre-formbuilder 在你已有业务上做功能扩展、字段裁剪、UI 适配、与内部账号 / 权限 / 日志系统的深度对接。

BUG 修复 & 性能优化

线上偶发问题、内存泄漏、慢查询、并发异常等排查修复;针对高流量场景做缓存、队列、索引层面的调优。

项目外包 & 长期维护

承接完整的项目从需求 → 设计 → 开发 → 上线 → 长期运维;也可按月提供技术保姆服务。

yvsm@zunyunkeji.com QQ:316430983 微信:yvsm316 西安尊云信息科技 · 专注 PHP / Go / 分布式系统研发

统计信息

  • 总下载量: 31
  • 月度下载量: 0
  • 日度下载量: 0
  • 收藏数: 5
  • 点击次数: 2
  • 依赖项目数: 0
  • 推荐数: 0

GitHub 信息

  • Stars: 5
  • Watchers: 1
  • Forks: 5
  • 开发语言: PHP

其他信息

  • 授权协议: GPL-2.0
  • 更新时间: 2017-06-10