Page 1 of 1
Using CGUserDirectory & CGBetterForms Together
Posted: Mon Mar 25, 2019 10:34 pm
by MantaPro
Replacing an old 1.10cmsms system that had FEU; CGUserDirectory and Formbuilder.
On one page I had (tabular) list of FEU users from a specified group; where the list was inside a form; on the end of each row was a checkbox. Usage was tick one or more boxes (to select those users for the action); submit the form; execute the form disposition UDT.
Tried a few things unsuccessfully so far in CMS2.2.9.1 with the latest FEW; CGUserDirectory and CGBetterForms. Tried the following, didn't work
- Created a CGBetterForm template with a simple <form>{CGUserDirectory group=$listgroup summarytemplate="ListArrears" sortby=$sort}<submit></form> structure but when CGBetterForm scans the template it rejects the embedded module
- I also tried moving all of the $user listing template out of CGuserDirectories template (it is empty other than it converts the $users variable that CGUserDirectory creates) convert it to a global; then with the CGBetterForms template insert all of the $user listing template including the <input type=checkbox..... between the <form> and the <submit> - the intention was from the page: {CGUserDirectory group=$listgroup summarytemplate="ListArrears" sortby=$sort} create the $users array but produce no output; then have {CGBetterForms form=.... which would output the form embedded within the tabular user list......but CGBetterForms doesn't seem to find the checkbox ??
Running out of ideas of how to get these to work together; I could go back to using FormBuilder for this or just wrap CGUserdirectory template in a form with a post url that processes the selected UIDs - but I suspect there is a much better way that I'm overlooking
Re: Using CGUserDirectory & CGBetterForms Together
Posted: Mon Mar 25, 2019 10:45 pm
by MantaPro
Back in CMSMS 1.10 + FEU + CGUserDirectory and Formbuilder, I had
Page content of
Code: Select all
{assign var="listgroup" value="Arrears2019"}
{FormBuilder form='arrears' lang='en_US'}
Then in FormBuilder, the "arrears" form, just had 3 fields: a Module Interface Field set to
Code: Select all
{CGUserDirectory group=$listgroup summarytemplate="ListArrears" sortby=$sort}
plus a hidden field with the groupID and the UDT disposition "field"
Then in the "ListArrears" CGUserDirectory template, in the main <tbody> it included
Code: Select all
<td width="5%">{$oneuser.id}</td>
<td>{$oneuser.properties.name}</td>
<td>{$oneuser.username}</td>
.
.
.
.
<td><input type="checkbox" value="{$oneuser.id}" name="{$FBid}[]" /></td>
Could carry on using Formbuilder; but I'd prefer t learn how to get CGBetterForms and CGUserDirectory to work together to achieve the same thing
Re: Using CGUserDirectory & CGBetterForms Together
Posted: Mon Mar 25, 2019 11:01 pm
by MantaPro
In CMSMS2.2.9.1 with recent FEU (2.13); CGUserDirector (1.5.1) & CGBetterForms 1.9.1 I tried the following - which didn't work
In the page content
etc
Then in my CGBetterForms template
Code: Select all
<form>
<input type="hidden" id="groupname" name="groupname" value="{$listgroup}">
{CGUserDirectory group=$listgroup summarytemplate="ListArrears" sortby=$sort}
<input type="submit">
</form>
Then in the CGUserDirectory template ListArrears, a tabular list of lists in the group where the <tbody> included
Code: Select all
<td>{$oneuser.id}</td>
<td>{$oneuser.username}</td>
<td><input type="checkbox" value="{$oneuser.id}" name="remove[]" /></td>
But when I scan the form template in CGBetterForms it rejects the embedded {CGUserDirectory ... tag
So I also tried relocating all of the CGUserDirectory template out of CGUD and embedding it directly in the form template aiming to invoke CGUserDirectory to populate the $user array (with no output) then have the CGBetterForm produce all of the userlist and form. CGBetterform scans the template but doesn't seem to be able to "see" the checkbox field that is within the foreach loop
Code: Select all
<form>
<input type="hidden" id="groupname" name="groupname" value="{$listgroup}">
<table>
<tr>
<th></th>
<th>Select</th>
</tr>
{foreach from=$users item='oneuser' name=foo}
<tr>
<td>{$oneuser.id}</td>
<td><input type="checkbox" value="{$oneuser.id}" name="remove[]" /></td>
</tr>
{/foreach}
</table>
<input type="submit">
</form>
Re: Using CGUserDirectory & CGBetterForms Together
Posted: Tue Mar 26, 2019 12:49 am
by DIGI3
When you call modules in the back end (which is what is happening when cgbf scans the form), you need to use {cms_module module='modulename'}. So in your case, in your CGBF form template, I would do something like:
Code: Select all
<input id="groupname" name="groupname" value="{$listgroup}" data-cgbf-selected="{$form_data->groupname}" data-cgbf-novalidate>
{cms_module module='CGUserDirectory' group=$listgroup summarytemplate="ListArrears" sortby=$sort}
</input>
Re: Using CGUserDirectory & CGBetterForms Together
Posted: Tue Mar 26, 2019 2:53 am
by MantaPro
Thanks for the reply DIGI3 - thanks for the "{cms_module module=..." tip.
Not sure about the code you suggested - it would be a list of (say 100) users in the middle of a single <input> tag - whereas I'm trying to get a CGBF <input> tag on each of the 100 lines
But taking on board your {cms_module module= tip. Here is the current state of play (stripped everything back to bare bones until I get this working)
Page content
Code: Select all
{assign var="listgroup" value="Arrears2013" scope="global"}
{CGBetterForms form='arrearsList'}
CGBF form "arrearsList"
Code: Select all
{cgbf_form_errors assign='errors'}
{if !empty($errors)}
<ul class="error">
{foreach $errors as $err}
<li>{$err}</li>
{/foreach}
</ul>
{/if}
<form>
<input type="hidden" id="groupname" name="groupname" value="{$listgroup}">
{cms_module module='CGUserDirectory' group=$listgroup summarytemplate="listArrears" sortby=$sort}
<input type="submit">
</form>
And in CGUD template "listArrears"
Code: Select all
<table>
{foreach from=$users item='oneuser' name=foo}
<tr>
<td>{$oneuser.id}</td>
<td><input type="checkbox" value="{$oneuser.id}" name="remove[]" data-cgbf-novalidate/></td>
</tr>
{/foreach}
</table>
<pre>
{$users|@var_dump}
</pre>
When I scan the form template in CGBF it throws approx 50 warnings which are all one the 2 types listed
Code: Select all
ERROR: htmlParseEntityRef: no name at about line 14372 column 36
ERROR: htmlParseEntityRef: no name at about line 14942 column 34
ERROR: htmlParseEntityRef: no name at about line 15001 column 36
ERROR: htmlParseEntityRef: no name at about line 15588 column 36
ERROR: htmlParseEntityRef: no name at about line 15645 column 38
Could not find a label for field "remove[]" at about line 6.
Could not find a label for field "remove[]" at about line 10.
Could not find a label for field "remove[]" at about line 14.
Could not find a label for field "remove[]" at about line 18.
Obviously there is no line 15645 !! LOL
And in the front end; it just shows a single checkbox and the var_dump outs NULL
Re: Using CGUserDirectory & CGBetterForms Together
Posted: Tue Mar 26, 2019 3:23 am
by DIGI3
Sorry, I was copying code from a similar instance I have but didn't finish changing it to match yours. The theory is still the same though.
Start with getting the form template to show properly on the front end before adding it to CGBF, just {include} it and get all of the html to validate. Make sure every input has a unique name.
Once the form is working properly there, then try it in CGBF. If it still doesn't work, perhaps share a link here with the aforementioned {include} call, no CGBF.
Re: Using CGUserDirectory & CGBetterForms Together
Posted: Tue Mar 26, 2019 3:25 am
by MantaPro
The desired end result (from my old CMS1.10 version) may make this all a bit more understandable
Trying to get a CGBF input checkbox in to the foreach loop that is within a CGUD list
(using CGUD is convenient - could omit it and do it all with the CGBF template using
Code: Select all
{feu_smarty::get_users_by_groupname($groupname[,$for_list])}
But I tried a simple test in the CGBF template of
Code: Select all
{$users=feu_smarty::get_users_by_groupname('Arrears2013')}
<form>
<table>
{foreach from=$users item='oneuser' name=foo}
<tr>
<td>{$oneuser.id}</td>
<td><input type="checkbox" value="{$oneuser.id}" name="remove[]" /></td>
</tr>
{/foreach}
</table>
<input type="submit">
</form>
CGBF doesn't seem to like form fields inside foreach loops
Re: Using CGUserDirectory & CGBetterForms Together
Posted: Tue Mar 26, 2019 3:32 am
by MantaPro
Thanks DIGI3 - I will as you suggest get the form rending as desire outside of CGBF i.e. a template with a <form>; the call to CGUD then the submit and </form>
Re: Using CGUserDirectory & CGBetterForms Together
Posted: Tue Mar 26, 2019 4:33 am
by MantaPro
Thanks DIGI3 - good advise - makes debugging more transparent (because if it doesn't work as an include then some basics are wrong)
Got a simple stripped down version of what I'm trying to do now working
it was a litany of user errors (me=stupid

)
This
{cms_module module='CGUserDirectory' group=$listgroup summarytemplate="listArrears" sortby=$sort}
Needed quotes around the variables i.e.
{cms_module module='CGUserDirectory' group="$listgroup" summarytemplate="listArrears" sortby="$sort"}
Also having striped back so much of the content in order to get the basics working I was no longer setting the $sort value and CGUD won't run with an empty sortby param
thanks again for all the help
Re: Using CGUserDirectory & CGBetterForms Together
Posted: Tue Mar 26, 2019 3:41 pm
by MantaPro
Sadly spoke too soon when I thought it was working - the lack of CGBF warning messages when scanning the template and the form rendering as expected lulled me in to a false sense of success
Still not there yet - issue is CGBF isn't "seeing" the <input type="checkbox" that is within the CGUD template
Here is a link to the page
http://www.mantapro.co.uk/index.php?page=arrears
Top form is
Code: Select all
{include file='cms_template:arrearsList2'}
Where template arrearsList2 is
Code: Select all
<form>
<input type="hidden" id="groupname" name="groupname" value="{$listgroup}">
{cms_module module='CGUserDirectory' group="$listgroup" summarytemplate="listArrears"}
<input type="submit">
</form>
And in the CGUD template, the key line of interest is
Code: Select all
<td><input type="checkbox" value="{$oneuser.id}" name="remove[]" data-cgbf-novalidate/></td>
The second form on the page is the CGBF form called in the page via
Code: Select all
{CGBetterForms form='arrearsList'}
Where the "arrearsList" form template contains
Code: Select all
{cgbf_form_errors assign='errors'}
{if !empty($errors)}
<ul class="error">
{foreach $errors as $err}
<li>{$err}</li>
{/foreach}
</ul>
{/if}
<form>
<input type="hidden" id="groupname" name="groupname" value="{$listgroup}">
{cms_module module='CGUserDirectory' group="$listgroup" summarytemplate="listArrears"}
<button type="reset">Reset</button>
<button type="submit">Submit</button>
</form>
CGBF scans the above form without throwing any warning messages, but the only field it is seeing is the hidden "groupname" field - it is not seeing the recursive "remove[]" checkbox that is within the CGUD template where the key line in that template is
Code: Select all
<td><input type="checkbox" value="{$oneuser.id}" name="remove[]" data-cgbf-novalidate/></td>
Initially, just to get this working the form disposition for this form simply sends me an email with $groupname but I also added a $remove|@var_dump in case I was lucky- so it is safe to submit this form
Using my browsers network inspector - both versions of the form send the necessary data but in the resultant email $groupname is Arrears2013 but $remove is not surprisingly NULL as it hasn't registered that field
Re: Using CGUserDirectory & CGBetterForms Together
Posted: Tue Mar 26, 2019 3:44 pm
by DIGI3
CGBF requires that every field has a unique name, could it be as simple as that? Currently they're all the same.
Re: Using CGUserDirectory & CGBetterForms Together
Posted: Tue Mar 26, 2019 4:05 pm
by MantaPro
Thanks for the reply DIGI3
I tried reverting to removing the quotes from around the CGUD call
{cms_module module='CGUserDirectory' group=$listgroup summarytemplate="listArrears"}
Throws loads of warning messages - but now at least it registers the "remove" checkbox. Now when I use the form the resultant email shows the var_dump of $remove is populated with the IDs selected
I understand your suggestion re. making the field name unique; but it is in effect created like this
Code: Select all
{foreach from=$users item='oneuser' name=foo}
<tr>
<td>{$oneuser.id}</td>
.
.
.
.
<td><input type="checkbox" value="{$oneuser.id}" name="remove[]" data-cgbf-novalidate/></td>
</tr>
{/foreach}
i.e. in the template, the checkbox occurs once so the name is unique; When the template is scanned it is one field with a unique name; when rendered the loop may iterate 6 times or 100 - it'll vary. When the form is submitted then $remove is an array and importantly in the form disposition I know what the name of submitted field is (i.e. $remove) whereas if I did this
Code: Select all
<td><input type="checkbox" value="{$oneuser.id}" name="remove{$oneuser.id}" data-cgbf-novalidate/></td>
</tr>
{/foreach}
Then I guess I can deduce the possible names of the fields submitted because I know the IDs of users in that Group - may be easier to live with the CGBF warnings
Re: Using CGUserDirectory & CGBetterForms Together
Posted: Tue Mar 26, 2019 4:14 pm
by DIGI3
Gotcha. You may be able to reduce the error messages with some of the cgbf- data attributes, but in the end they're only for your reference anyway.
If you are for sure getting false positives and can recreate them on a more simple form, by all means file a bug report or feature request. I've made my share

Re: Using CGUserDirectory & CGBetterForms Together
Posted: Tue Mar 26, 2019 4:15 pm
by MantaPro
Not out of the woods yet though
If I select say 5 IDs and submit them - my browser Network inspector correctly shows that a 5 entry array is sent with properly set ID data
But in the email disposition from CGBF the arrears to be truncated to a maximum of 3 entries. Strange