Jump to content
OLSA

Module: ConfigurationForm (multiple fields container)

Recommended Posts

Hello for all,

ConfigurationForm fieldtype module is one my experiment from 2016.
Main target to build this module was to store multiple setup and configuration values in just 1 field and avoid to use 1 db table to store just single "number of items on page", or another db table to store "layout type" etc. Thanks to JSON formatted storage this module can help you to reduce number of PW native fields in project, save DB space, and reduce number of queries at front-end.

Install and setup:

  1. Download (at the bottom ), unzip and install like any other PW module (site/modules/...).
  2. Create some filed using this type of field (ConfigurationForm Fieldtype)
  3. Go to field setup Input tab and drag some subfields to container area (demo).
  4. Set "Name" and other params for subfields
  5. Save and place field to templates ("Action tab")

How to use it:

In my case, I use it to store setup and configurations values, but also for contact details, small content blocks... (eg. "widgets").

Basic usage example:

ConfigForm fieldtype "setup" has subfields:

"limit", type select, option values: 5, 10, 15, 20
"sort", type select, option values: "-date", "date",  "-sort", "sort"

// get page children (items)
$limit = isset($page->setup->limit) ? $page->setup->limit : 10;
$sort = isset($page->setup->sort) ? $page->setup->sort : '-sort';
$items = $page->children("limit=$limit, sort=$sort");

 

Screenshots:

Field setupSome page setupVariant SEO and setups fieldsCompact view option

Contact details (none compact view)Services using repeater and configform fieldtypeRepeater label as subfield value

 

Notes:

  • Provide option to search inside subfields
  • Provide multilanguage inputs for text and textarea field types
  • Provide option for different field layout per-template basis
  • Do not place/use field type "Button" or "File input" because it won't works.
  • Please read README file for more details and examples

Module use JSON format to store values. Text and textarea field types are multilanguage compatible, but please note that main target for this module was to store setup values and small content blocks and save DB space. Search part inside JSON is still a relatively new in MySQL (>=5.77) and that's on you how and for what to use this module.

Thanks:

Initial point for this fieldtype was jQuery plugin FormBuiled and thanks to Kevin Chappel for this plugin.
In field type "link" I use javascript part from @marcostoll module and thanks to him for that part.

Download:

FieldtypeConfigForm.zip

Edit: 14. August 2018. please delete/uninstall previously downloaded zip

Regards.

   
  • Like 19
  • Thanks 4

Share this post


Link to post
Share on other sites

Here are more details and some news about this module.

What's new (14. August 2018.):
- fix small bug
- search by subfields
- different layouts per-template basis

Examples:

1) 1 single field for configuration and setup instead 7 PW native fields

On "Home" administration page want to have global config options (stylesheet, development or production mode), and SEO settings fields.
On category pages need to have options to change number of children in list, provide option to select different layouts, and SEO settings fields.
Conclusion, need to have 7 fields: stylesheet (select), development (select or check), SEO fields (eg. title, description and robots), limit, layout.

Create field "setup" with all needed subfields:

field-setup-1.thumb.png.cd83abe872c74a369f22dd5087871f7e.pngfield-setup-2.thumb.png.56b8dba113a9032baaaa389d48417cec.pngfield-setup-3.thumb.png.08dc69b43a6f630ea813835cbf76d1b8.png

But also want to have different field layout inside Home and category pages.
For that we use "Compact view" inside template setup.
Result, same field but with different inputs and layouts.

layout-1.thumb.png.7f139c6063d9069d3f11c8bfe7657c6e.pnglayout-2.thumb.png.01a23e9c942401a0d8de7f5a8a69a43d.png

 

On site are dozen of categories and want to find where are used grid and where list layout.
Or, website is in still development mode and want to find NOINDEX categories, etc...


search-by-subfields-1.thumb.png.5551d4d98c4d402c3227edf550d988f0.png

 

2) Multiple different textareas on "basic-page" and "basic-page-2" templates using 1 single field
Task:
 - textarea1, textarea2 and textarea3 on basic-page template
 - textarea1, textarea4, textarea5 on basic-page-2 template
 - all that with 1 PW field

 Create field "content" with 5 textarea field types (textarea1...textarea5)
 
 Set Visibility condition like this:
 basic-page=textarea1, textarea2, textarea3
 basic-page-2=textarea1, textarea4, textarea5
 
 Inside Action tab add field to templates basic-page and basic-page-2.
 Later in page administration are only desired textarea inputs.

text-areas-1.thumb.png.636c0e7fb746c7a30f36e9c3769eb256.pngtext-areas-2.thumb.png.2296d1ffed301e4a6f8a8de684d4ef43.png

 
Search: find all pages where textarea1 contain word "Toronto"

 $items = $pages->find('content.textarea1*=Toronto');

Or in admin backend using lister:

search-by-subfields-2.thumb.png.bcffc5304210ca7f7cf3beae009a1c5c.png

In front side:

$selector = 'content.textarea1*=Toronto';
$items = $pages->find($selector);

if($items->count){
	echo "<h2>Find items: {$items->count}</h2>";
	echo "Selector:<pre>$selector</pre>";	
	foreach($items as $item){		
		echo $item->title .', template: '. $item->template->name;
		echo '<br />';
		
	}
}

search-by-subfields-3.png.9bbca688f6e31d6d649a66da5069c7cb.png

Note: this example is only for demostrations and I didn't test this in case of few thousands pages.

 

  • Like 5

Share this post


Link to post
Share on other sites

Great work! Thanks for sharing.

Unfortunately, I didn't have time yet to try this out, but I'll give it a go in the next couple of days.

I can imagine quite a few real-world usage scenarios for this.

  • Like 2

Share this post


Link to post
Share on other sites

Zdravo Sasa, kako je sunce u Crnoj Gori?  😄

I installed your module and played around a bit. Looks good so far.

Only thing I spotted: the PW width settings are not being displayed as intended, when I choose "compact view". In normal view, it's working fine.

And also, some elements are a bit too close to each other, when choosing compact view: (checkbox and radio labels)

compact-view.thumb.PNG.251c03bf1af2c8c1ad2920dffd21efdf.PNG

  • Like 1

Share this post


Link to post
Share on other sites

Dragane, odlicno, samo da je malo manje vruce ;)

CompactView is html table view and idea for that type of layout was to use it in cases where are inputs closely related (eg. some contact details), and inside repeaters because don't take too much space (can open few repeater items, and at the same time, view fields in all of them).

I missed to write in notes that PW Width value is not used inside CompactView layout.
Sorry but it's possible that I skiped to write and some other notes, and feel free to ask me anything that is not clear or confusing.

Fields what I used in almost 90% are: select, text, textarea, page and link. Radio and checkboxes very, very rarely (can't remeber), and in that case I prefer to use select.

Please can you try to add to the end of module css file (module  directory... site/modules/FieldtypeConfigForm/assets/css/admin.css) this few lines:

.CompactView .InputfieldCheckboxesStacked, .CompactView .InputfieldRadiosStacked {list-style:none;padding-left:0;}
.CompactView .InputfieldCheckboxesStacked input, .CompactView .InputfieldRadiosStacked input {margin-right:10px;}

, and after it refresh browser page (CTRL+F5) and check if it will be better?

Thanks and regards!

  • Like 3

Share this post


Link to post
Share on other sites

Yep, much better. I also removed the 12px font-size for the compact view label, it somehow looks weird to me if it's smaller than the rest, but that's just personal preference.

Thanks for clarifying that the width is ignored in compact view on purpose.

  • Like 1

Share this post


Link to post
Share on other sites
On 8/10/2018 at 7:34 AM, OLSA said:

Notes:

  • Provide option to search inside subfields
  • Provide multilanguage inputs for text and textarea field types
  • Provide option for different field layout per-template basis
  • Do not place/use field type "Button" or "File input" because it won't works.
  • Please read README file for more details and examples

May I suggest to simply exclude button and file inputs - it's kinda pointless to see them there as available input fields, when in fact they don't (yet?) work.

And the mulitlanguage part would be really really awesome. Most sites we build are multilang, so this feature would be almost a must-have, rather than a nice-to-have.

Did you post your module to the official PW module directory? https://modules.processwire.com/add/
That way, it would be easier for other people to find your module. And (afaik) this is a pre-requisite if you want people to use the "check for updates" feature in the PW-backend.

Zelim ti lep vikend 🙂

 

  • Like 2

Share this post


Link to post
Share on other sites

Zdravo Dragane,

I totally agree with you, and I'm aware of all imperfections, but I use it last 2 years in all my projects (multilanguage) and it's play important role in all of them.
News is that I am started with development of different version of that module and it's possible that I will include all suggestion in that version, or will do that in next release of current version, and after it post it to Github and in PW module directory.

Inputs like text and textarea are multilanguage, but labels are not because that part depends on jQuery FormBuilder plugin (in my case, I write labels in administration default language).

I really appreciate all the suggestions to make this module better and thanks for that!

  • Like 1

Share this post


Link to post
Share on other sites

Evo me opet 🙂

I encountered a strange problem today when I wanted to setup something with required fields:

I first hit the module's save-button, then I hit the PW field-save button. And PW can't save the field, because I get errors from the first field that is required (I don't want to prepopulate the fields or use placeholders).

This is some kind of a Catch-22 problem I guess 🙂

And also, I see JS errors in Chrome console:

config-errors-JS.thumb.PNG.e714fe59eff1b04f6f756b2619818c17.PNG

 

When I want to edit a page where I have this field inside, Tracy reports this error:

ErrorException: count(): Parameter must be an array or an object that implements Countable in /home/sitecom/www/mysite/site/modules/FieldtypeConfigForm/FieldtypeConfigForm.module:69
Stack trace:
#0 [internal function]: Tracy\Bar->Tracy\{closure}(2, 'count(): Parame...', '/home/zeixcom/w...', 69, Array)
#1 /home/sitecom/www/mysite/site/modules/FieldtypeConfigForm/FieldtypeConfigForm.module(69): count(Object(stdClass))
#2 /home/sitecom/www/mysite/wire/core/Wire.php(389): ProcessWire\FieldtypeConfigForm->___formatValue(Object(ProcessWire\Page), Object(ProcessWire\Field), Object(ProcessWire\ConfigForm))
#3 /home/sitecom/www/mysite/wire/core/WireHooks.php(723): ProcessWire\Wire->_callMethod('___formatValue', Array)
#4 /home/sitecom/www/mysite/wire/core/Wire.php(413): ProcessWire\WireHooks->runHooks(Object(ProcessWire\FieldtypeConfigForm), 'formatValue', Array)
#5 /home/sitecom/www/mysite/wire/core/Page.php(1436): ProcessWire\Wire->_callHookMethod('formatValue', Array)
#6 /home/sitecom/www/mysite/wire/core/Page.php(1364): ProcessWire\Page->formatFieldValue(Object(ProcessWire\Field), Object(ProcessWire\ConfigForm))
#7 /home/sitecom/www/mysite/wire/core/Page.php(1116): ProcessWire\Page->getFieldValue('setup')
#8 /home/sitecom/www/mysite/wire/core/Page.php(1600): ProcessWire\Page->get('setup')
#9 /home/sitecom/www/mysite/site/assets/cache/FileCompiler/site/modules/TracyDebugger/panels/RequestInfoPanel.php(470): ProcessWire\Page->getFormatted('setup')
#10 /home/sitecom/www/mysite/site/assets/cache/FileCompiler/site/modules/TracyDebugger/tracy-master/src/Tracy/Bar.php(159): RequestInfoPanel->getPanel()
#11 /home/sitecom/www/mysite/site/assets/cache/FileCompiler/site/modules/TracyDebugger/tracy-master/src/Tracy/Bar.php(108): Tracy\Bar->renderPanels()
#12 /home/sitecom/www/mysite/site/assets/cache/FileCompiler/site/modules/TracyDebugger/TracyDebugger.module(1487): Tracy\Bar->render()
#13 /home/sitecom/www/mysite/wire/core/Wire.php(383): TracyDebugger->sessionHandlerDBAjaxFix(Object(ProcessWire\HookEvent))
#14 /home/sitecom/www/mysite/wire/core/WireHooks.php(825): ProcessWire\Wire->_callMethod('sessionHandlerD...', Array)
#15 /home/sitecom/www/mysite/wire/core/Wire.php(442): ProcessWire\WireHooks->runHooks(Object(ProcessWire\ProcessWire), 'finished', Array)
#16 /home/sitecom/www/mysite/wire/core/ProcessWire.php(603): ProcessWire\Wire->__call('finished', Array)
#17 /home/sitecom/www/mysite/wire/core/ProcessWire.php(499): ProcessWire\ProcessWire->__call('finished', Array)
#18 /home/sitecom/www/mysite/wire/modules/Process/ProcessPageView.module(254): ProcessWire\ProcessWire->setStatus(16)
#19 /home/sitecom/www/mysite/wire/core/Wire.php(380): ProcessWire\ProcessPageView->___finished()
#20 /home/sitecom/www/mysite/wire/core/WireHooks.php(723): ProcessWire\Wire->_callMethod('___finished', Array)
#21 /home/sitecom/www/mysite/wire/core/Wire.php(442): ProcessWire\WireHooks->runHooks(Object(ProcessWire\ProcessPageView), 'finished', Array)
#22 /home/sitecom/www/mysite/index.php(56): ProcessWire\Wire->__call('finished', Array)
#23 {main}

Any ideas? Did you ever stumble across such a situation?

Edited by dragan
added Tracy Debugger error msg

Share this post


Link to post
Share on other sites

Hi Dragane,

sorry for the delayed response (I am on vacation until September 1st).

If that's  JS errors are in Chrome console inside field setup, that might be in relation with required attribute and Chrome browser (here are more details), but if you insert any values in setup "form" fields maybe you can "skip" that and PW will save field and it's subfields? Also, as a result of the first , maybe you have "empty" field (without subfields), and that cause second error (never noticed before, but I'll investigate that).

Here is one important detail that you probably didn't notice, and my fault because I didn't mention, required attribute is not in use in current version.

There are few options and buttons what are not in use and I didn't remove because my first plan was to use them all for fields (eg. "Required",  "Limit access..." ) or for new features.

Share this post


Link to post
Share on other sites

This module is great, very useful and i'm using it on a project; I guess my PHP version (7.2.10 ) doesn't like this: (FieldtypeConfigForm, line 69)

if(count($values)){

but this works

if(wireCount($values)){

 

  • Like 2

Share this post


Link to post
Share on other sites

Hey!
Thank you for this great module, I use it as part of a repeater item (for settings, to save some white space and grouping the settings).

Now I tried to echo the Value of a select option (Dropdown) like this:
{$item->grid_settings->gridsize->title}

gridsize is the name of my select field. And grid_settings is the name of my ConfigurationForm field (which contain multiple select fields). Item is the repeater item.

But this is not working. What Iam missing here?
Also is it possible to preselect an option?

Share this post


Link to post
Share on other sites

Hello @jploch

in case of select field, you can get only selected option value (and not title/text) or in your case:

$grid_size = $item->grid_settings->gridsize;

Share this post


Link to post
Share on other sites
On 9/27/2018 at 2:22 PM, jploch said:

Also is it possible to preselect an option? 

Preselect option, currently, only in case when you have option value as null "0", as example your "gridsize" field:

Label: "Grid size"

-- option value: 0, option text: Default
-- option value: 1, option text: Grid size 1
-- option value: 2, option text: Grid size 2

In that case, preselected value in admin backend would be "Default".
Later in your code:

if ($item->grid_settings->gridsize){
// not default (not preselected value)
...
} else {
// default
...
}

But there is and "mix" variant, example, some select field with name background:

label: "Background color"

-- option value: 0, text: Default
-- option value: black, text: Black
-- option value: orange, text: Orange

* preselected text : "Default"

Later in code:

<?php
// configuration form field "settings" with select subfield "background"
$background = $page->settings->background ? '-' . $page->settings->background : '';
?>
<div class="bgn<?php echo $background;?>">

* div can have css class values: bgn, bgn-black, bgn-orange

Regards.

  • Like 1

Share this post


Link to post
Share on other sites

Really like this module, using it to make a visual builder however I encountered that the uploading of files doesn't work. No errors is thrown.

It starts the ajax-upload but when it should be done it just disappear and the file isn't uploaded.

Currently debugging the issue. Will get back as soon as I find the issue.

But also wanted to see if anyone else encountered this?

Share this post


Link to post
Share on other sites

Sorry, above it says:

Quote

Do not place/use field type "Button" or "File input" because it won't works .

 

Share this post


Link to post
Share on other sites
Just now, gmclelland said:

Sorry, above it says:

 

Yes, I just read that! 

I'll dig into solving that 🙂 

Share this post


Link to post
Share on other sites

@OLSA Hey man, I just found your amazing module while looking for an easy way to add a bunch of settings to a Profile Configuration page and I am trully impressed. I've seen some other great modules which I initially planned to use but to have a drag&drop functionality would make the development much easier for me (maybe I am too lazy).

I am testing it now and will see how will it work. At least I can combine the file upload/image uplad default PW fields with the "custom field" of your module and avoid the need of adding image paths etc.

Thank you for this masterpiece!

  • Like 1

Share this post


Link to post
Share on other sites

After a few quick tests, I found it pretty straight forward to echo the content of text/textarea.

In addition to the present functions of the module, it would be great if we could set the default state of the field (open, closed) as well as to have some logic of fields appearance based on other fields value (like it is with regular fields)

Share this post


Link to post
Share on other sites
On 9/21/2018 at 9:32 PM, Macrura said:

if(wireCount($values)){

 

I had a similar issue, but in my scenario (with no module modifications) the line causing it was 58

if(count($values)){

I can confirm that changing the line to @Macrura correction eliminated the error in my logs.

Share this post


Link to post
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.


  • Recently Browsing   0 members

    No registered users viewing this page.

  • Similar Content

    • By gebeer
      I am happy to present my new fieldtype FieldtypeImageFromPage. It is made up of 2 modules:
      Fieldtype Image Reference From Another Page is a Fieldtype that stores a reference to a single image from another page. The image can be selected with the associated Inputfield.
      Inputfield Select Image From Page is an Inputfield to select a single image from images on a predefined page and it's children.
      And there also is a helper module that takes care of cleanup tasks.
      This module evolved out of a discussion about my other Module FieldtypeImagePicker.  It caters for use cases where a set of images is being reused multiple times across a site. With this fieldtype these images can be administered through a chosen page. All images uploaded to that page will be available in the inputfield.
      When to use ?
      Let editors choose an image from a set of images that is being used site-wide. Ideal for images that are being re-used across the site.
      Suited for images that are used on multiple pages throughout the site (e.g. icons).
      Other than the native ProcessWire images field, the images here are not stored per page. Only references to images on another page are stored. This has several advantages:
      one central place to organize images when images change, you only have to update them in one place. All references will be updated, too. (Provided the name of the image that has changed stays the same) Features
      Images can be manipulated like native ProcessWire images (resizing, cropping etc.) Image names are fully searchable through the API Accidental image deletion is prevented. When you want to delete an image from one of the pages that hold your site-wide images, the module searches all pages that use that image. If any page contains a reference to the image you are trying to delete, deletion will be prevented. You will get an error message to help you edit those pages and remove references there before you can finally delete the image. How to install and setup
      Download and install this module like any other modules in ProcessWire Create a page in the page tree that will hold your images. This page's template must have an images field Upload some images to the page you created in step 2 Create a new field. As type choose 'Image Reference From Another Page'. Save the field. In 'Details' Tab of the field choose the page you created in step 2 Click Save button Choose the images field name for the field that holds your images (on page template from step 2) Click Save button again Choose whether you want to include child pages of page from step 2 to supply images Add the field to any template You are now ready to use the field View of the inputfield on the page edit screen:

      View of the field settings

      The module can be installed from this github repo. Some more info in the README there, too.
      In my tests it was fairly stable. After receiving your valued feedback, I will eventually add it to the modules directory.
      My ideas for further improvement:
      - add ajax loading of thumbnails
      Happy to hear your feedback!
       
    • By gebeer
      Although the PW backend is really intuitive, ever so often my clients need some assistance. Be it they are not so tech savvy or they are not working in the backend often.
      For those cases it is nice to make some help videos available to editors. This is what this module does.
      ProcessHelpVideos Module
      A Process module to display help videos for the ProcessWire CMS. It can be used to make help videos (screencasts) available to content editors.
      This module adds a 'Help Videos" section to the ProcessWire backend. The help videos are accessible through an automatically created page in the Admin page tree. You can add your help videos as pages in the page tree. The module adds a hidden page to the page tree that acts as parent page for the help video pages. All necessary fields and templates will be installed automatically. If there are already a CKEditor field and/or a file field for mp4 files installed in the system, the module will use those. Otherwise it will create the necessary fields. Also the necessary templates for the parent help videos page and it's children are created on module install. The module installs a permission process-helpvideos. Every user role that should have access to the help video section, needs this permission. I use the help video approach on quite a few production sites. It is stable so far and well received by site owners/editors. Up until now I installed required fields, templates and pages manually and then added the module. Now I added all this logic to the install method of the module and it should be ready to share.
      The module and further description on how to use it is available on github: https://github.com/gebeer/ProcessHelpVideos
      If you like to give it a try, I am happy to receive your comments/suggestions here.
    • By Robin S
      A module created in response to the topic here:
      Page List Select Multiple Quickly
      Modifies PageListSelectMultiple to allow you to select multiple pages without the tree closing every time you select a page.
      The screencast says it all:

       
      https://github.com/Toutouwai/PageListSelectMultipleQuickly
      https://modules.processwire.com/modules/page-list-select-multiple-quickly/
    • By gebeer
      Hello all,
      sharing my new module FieldtypeImagePicker. It provides a configurable input field for choosing any type of image from a predefined folder.
      The need for it came up because a client had a custom SVG icon set and I wanted the editors to be able to choose an icon in the page editor.
      It can also be used to offer a choice of images that are used site-wide without having to upload them to individual pages.
      There are no image manipulation methods like with the native PW image field.
      Module and full description can be found on github https://github.com/gebeer/FieldtypeImagePicker
      Kudos to @Martijn Geerts. I used his module FieldTypeSelectFile as a base to build upon.
      Here's how the input field looks like in the page editor:

      Hope it can be of use to someone.
      If you like to give it a try, I'm happy to hear your comments or suggestions for improvement. Eventually this will go in the module directory soon, too.
    • By bernhard
      @Sergio asked about the pdf creation process in the showcase thread about my 360° feedback/survey tool and so I went ahead and set my little pdf helper module to public.
      Description from PW Weekly:
       
      Modules Directory: https://modules.processwire.com/modules/rock-pdf/
      Download & Docs: https://github.com/BernhardBaumrock/RockPDF
       
      You can combine it easily with RockReplacer: 
      See also a little showcase of the RockPdf module in this thread:
       
×
×
  • Create New...