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 17
  • Thanks 3

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

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 Robin S
      A community member raised a question and I thought a new sanitizer method for the purpose would be useful, hence...
      Sanitizer Transliterate
      Adds a transliterate method to $sanitizer that performs character replacements as defined in the module config. The default character replacements are based on the defaults from InputfieldPageName, but with uppercase characters included too.
      Usage
      Install the Sanitizer Transliterate module.
      Customise the character replacements in the module config as needed.
      Use the sanitizer on strings like so:
      $transliterated_string = $sanitizer->transliterate($string);
       
      https://github.com/Toutouwai/SanitizerTransliterate
      https://modules.processwire.com/modules/sanitizer-transliterate/
       
    • By dimitrios
      Hello,
      this module can publish content of a Processwire page on a Facebook page, triggered by saving the Processwire page.
      To set it up, configure the module with a Facebook app ID, secret and a Page ID. Following is additional configuration on Facebook for developers:
      Minimum Required Facebook App configuration:
      on Settings -> Basics, provide the App Domains, provide the Site URL, on Settings -> Advanced, set the API version to 2.10, add Product: Facebook Login, on Facebook Login -> Settings, set Client OAuth Login: Yes, set Web OAuth Login: Yes, set Enforce HTTPS: Yes, add "http://www.example.com/processwire/page/" to field Valid OAuth Redirect URIs. This module is configurable as follows:
      Templates: posts can take place only for pages with the defined templates. On/Off switch: specify a checkbox field that will not allow the post if checked. Specify a message and/or an image for the post.
      Usage
      edit the desired PW page and save; it will post right after the initial Facebook log in and permission granting. After that, an access token is kept.
       
      Download
      PW module directory: http://modules.processwire.com/modules/auto-fb-post/ Github: https://github.com/kastrind/AutoFbPost   Note: Facebook SDK for PHP is utilized.


    • By thomasaull
      I created a little helper module to trigger a CI pipeline when your website has been changed. It's quite simple and works like this: As soon as you save a page the module sets a Boolean via a pages save after hook. Once a day via LazyCron the module checks if the Boolean is set and sends a POST Request to a configurable Webhook URL.
      Some ideas to extend this:
      make request type configurable (GET, POST) make the module trigger at a specified time (probably only possible with a server cronjob) trigger manually Anything else? If there's interest, I might put in some more functionality. Let me know what you're interested in. Until then, maybe it is useful for a couple of people 🙂
      Github Repo: https://github.com/thomasaull/CiTrigger
    • By Robin S
      I created this module a while ago and never got around to publicising it, but it has been outed in the latest PW Weekly so here goes the support thread...
      Unique Image Variations
      Ensures that all ImageSizer options and focus settings affect image variation filenames.

      Background
      When using methods that produce image variations such as Pageimage::size(), ProcessWire includes some of the ImageSizer settings (height, width, cropping location, etc) in the variation filename. This is useful so that if you change these settings in your size() call a new variation is generated and you see this variation on the front-end.
      However, ProcessWire does not include several of the other ImageSizer settings in the variation filename:
      upscaling cropping, when set to false or a blank string interlace sharpening quality hidpi quality focus (whether any saved focus area for an image should affect cropping) focus data (the top/left/zoom data for the focus area) This means that if you change any of these settings, either in $config->imageSizerOptions or in an $options array passed to a method like size(), and you already have variations at the requested size/crop, then ProcessWire will not create new variations and will continue to serve the old variations. In other words you won't see the effect of your changed ImageSizer options on the front-end until you delete the old variations.
      Features
      The Unique Image Variations module ensures that any changes to ImageSizer options and any changes to the focus area made in Page Edit are reflected in the variation filename, so new variations will always be generated and displayed on the front-end.
      Installation
      Install the Unique Image Variations module.
      In the module config, set the ImageSizer options that you want to include in image variation filenames.
      Warnings
      Installing the module (and keeping one or more of the options selected in the module config) will cause all existing image variations to be regenerated the next time they are requested. If you have an existing website with a large number of images you may not want the performance impact of that. The module is perhaps best suited to new sites where image variations have not yet been generated.
      Similarly, if you change the module config settings on an existing site then all image variations will be regenerated the next time they are requested.
      If you think you might want to change an ImageSizer option in the future (I'm thinking here primarily of options such as interlace that are typically set in $config->imageSizerOptions) and would not want that change to cause existing image variations to be regenerated then best to not include that option in the module config after you first install the module.
       
      https://github.com/Toutouwai/UniqueImageVariations
      https://modules.processwire.com/modules/unique-image-variations/
    • By Sebi
      I've created a small module which lets you define a timestamp after which a page should be accessible. In addition you can define a timestamp when the release should end and the page should not be accessable any more.
      ProcessWire-Module: http://modules.processwire.com/modules/page-access-releasetime/
      Github: https://github.com/Sebiworld/PageAccessReleasetime
      Usage
      PageAccessReleasetime can be installed like every other module in ProcessWire. Check the following guide for detailed information: How-To Install or Uninstall Modules
      After that, you will find checkboxes for activating the releasetime-fields at the settings-tab of each page. You don't need to add the fields to your templates manually.
      Check e.g. the checkbox "Activate Releasetime from?" and fill in a date in the future. The page will not be accessable for your users until the given date is reached.
      If you have $config->pagefileSecure = true, the module will protect files of unreleased pages as well.
      How it works
      This module hooks into Page::viewable to prevent users to access unreleased pages:
      public function hookPageViewable($event) { $page = $event->object; $viewable = $event->return; if($viewable){ // If the page would be viewable, additionally check Releasetime and User-Permission $viewable = $this->canUserSee($page); } $event->return = $viewable; } To prevent access to the files of unreleased pages, we hook into Page::isPublic and ProcessPageView::sendFile.
      public function hookPageIsPublic($e) { $page = $e->object; if($e->return && $this->isReleaseTimeSet($page)) { $e->return = false; } } The site/assets/files/ directory of pages, which isPublic() returns false, will get a '-' as prefix. This indicates ProcessWire (with activated $config->pagefileSecure) to check the file's permissions via PHP before delivering it to the client.
      The check wether a not-public file should be accessable happens in ProcessPageView::sendFile. We throw an 404 Exception if the current user must not see the file.
      public function hookProcessPageViewSendFile($e) { $page = $e->arguments[0]; if(!$this->canUserSee($page)) { throw new Wire404Exception('File not found'); } } Additionally we hook into ProcessPageEdit::buildForm to add the PageAccessReleasetime fields to each page and move them to the settings tab.
      Limitations
      In the current version, releasetime-protected pages will appear in wire('pages')->find() queries. If you want to display a list of pages, where pages could be releasetime-protected, you should double-check with $page->viewable() wether the page can be accessed. $page->viewable() returns false, if the page is not released yet.
      If you have an idea how unreleased pages can be filtered out of ProcessWire selector queries, feel free to write an issue, comment or make a pull request!
×
×
  • Create New...