Hi. I'm running CMS Made Simple 2.1.6. PHP version is 5.5.38 I am running FormBuilder 0.8.1.6 and CMSMailer 6.2.14
I tried using the year pulldown type in FormBuilder and specified the end year to select from. The year pulldown works with allowed selection from current year descending to the declared end year.
Is there a way for the year pulldown selection to start in the future (i.e. beyond current year)? Has anyone come across a similar situation?
Thanks for any feedback.
Form Builder - Year pulldown
Re: Form Builder - Year pulldown
One way, I suppose, would be to use a standard pull down field and manually enter the years to show in the list.
To copy System Information to the forum:
https://docs.cmsmadesimple.org/troubles ... nformation
CMS Made Simple Geekmoots attended:
Nottingham, UK 2012 | Ghent, Belgium 2015 | Leicester, UK 2016
https://docs.cmsmadesimple.org/troubles ... nformation
CMS Made Simple Geekmoots attended:
Nottingham, UK 2012 | Ghent, Belgium 2015 | Leicester, UK 2016
Re: Form Builder - Year pulldown
There is another way to accomplish this, if there weren't a small flaw in the current version of FormBuilder
With the Field Type: "-Module Interface Field" you can call a UDT.
The UDT can output your dropdown like this
It's just that the smarty variable {$FBid} should be available, which isn't currently
http://dev.cmsmadesimple.org/bug/view/11327
With the Field Type: "-Module Interface Field" you can call a UDT.
The UDT can output your dropdown like this
Code: Select all
$FBid = $smarty->get_template_vars('FBid'); // get the field id
$year = Date('Y'); // get current year
$selected = ' selected="selected"';
echo '<div>
<label for="'.$FBid.'">Select Year</label>
<select class="cms_dropdown" name="'.$FBid.'" id="'.$FBid.'">';
//create 10 dropdown items
for ($i = 0; $i <= 10; $i++) {
echo '<option value="'.($year+$i).'"'.$selected.'>'.($year+$i).'</option>';
$selected = '';
}
echo '</select>
</div>';
http://dev.cmsmadesimple.org/bug/view/11327
Re: Form Builder - Year pulldown
FormBuilder has a form template that you can (and should) customize at will, thus you can actually use any valid HTML per field as you wish. So using an UDT as Jos has suggested or even just using the full HTML as paulbaker also suggested is equally valid. However in the case of jos' UDT I would call it directly from the form template instead of using a Field Type: "-Module Interface Field" as he suggested (btw Jos, thanks for catching that bug, I'll investigate it asap, although we will probably only fix it for next major release of FB). By calling the UDT on the form template you could pass the field id as a parameter for the UDT as well as the action id which is also necessary for the form to be processed. The UDT would then replace the field in the form template, something along the lines of (assuming you are still using the standard generated template for the form):
- where you find
- replace whith
- further down where you find
- replace with
Note: the code is not tested and you need to replace the names of the filed and that of the UDT accordingly. An additional tweak to the UDT would still be needed:
Again not tested, it's just a starting point... and if you have further customized the form template you'll have to figure out how to adapt it.
All that said, the field could actually have a more versatile approach and that will be taken in consideration too for next major version of FB.
- where you find
Code: Select all
{foreach from=$fields item=entry}
{if $entry->display == 1}- replace whith
Code: Select all
{foreach from=$fields item=entry}
{if $entry->id == $myyearpulldownfieldname->id}
{myyearpulldownudt id="{$actionid}{$entry->id}"}
{else}
{if $entry->display == 1}Code: Select all
{/if}
{/foreach}- replace with
Code: Select all
{/if}
{/if}
{/foreach}Code: Select all
//$FBid = $smarty->get_template_vars('FBid'); // get the field id
$FBid = isset($params['id']) ? $params['id'] : ''; // get the field id new version
$year = Date('Y'); // get current year
$selected = ' selected="selected"';
echo '<div>
<label for="'.$FBid.'">Select Year</label>
<select class="cms_dropdown" name="'.$FBid.'" id="'.$FBid.'">';
//create 10 dropdown items
for ($i = 0; $i <= 10; $i++) {
echo '<option value="'.($year+$i).'"'.$selected.'>'.($year+$i).'</option>';
$selected = '';
}
echo '</select>
</div>';All that said, the field could actually have a more versatile approach and that will be taken in consideration too for next major version of FB.
"There are 10 types of people in this world, those who understand binary... and those who don't."
* by the way: English is NOT my native language (sorry for any mistakes...).
Code of Condut | CMSMS Docs | Help Support CMSMS
My developer Page on the Forge
GeekMoot 2015 in Ghent, Belgium: I was there!
GeekMoot 2016 in Leicester, UK: I was there!
DevMoot 2023 in Cynwyd, Wales: I was there!
* by the way: English is NOT my native language (sorry for any mistakes...).
Code of Condut | CMSMS Docs | Help Support CMSMS
My developer Page on the Forge
GeekMoot 2015 in Ghent, Belgium: I was there!
GeekMoot 2016 in Leicester, UK: I was there!
DevMoot 2023 in Cynwyd, Wales: I was there!
-
calguy1000
- Support Guru

- Posts: 8169
- Joined: Tue Oct 19, 2004 6:44 pm
Re: Form Builder - Year pulldown
The provided solutions are WAY too over complicated.
There is a simple rule if using UDT's. UDT's should not output HTML, just data.
So it's a 2 step process:
a: Create a UDT that returns an array of the years you want to select.
b: Modify the formbuilder template to call that UDT, and provide the output of it to {html_options} to build a dropdown. Easy.
There is a simple rule if using UDT's. UDT's should not output HTML, just data.
So it's a 2 step process:
a: Create a UDT that returns an array of the years you want to select.
b: Modify the formbuilder template to call that UDT, and provide the output of it to {html_options} to build a dropdown. Easy.
Code: Select all
// udt - untested
$this_year=Date('Y');
$start_year=$this_year-10; // for example
$end_year=$this_year+10; // for example
$out = [];
for( $yr = $start_year; $yr <= $end_year; $yr++ ) {
$out[$yr] = $yr;
}
if( isset($params['assign']) ) {
$smarty->assign($params['assign'],$out);
} else {
return $out;
}Code: Select all
{* form template -- untested *}
{foreach from=$fields item=entry}
{if $entry->id == $myyearpulldownfieldname->id}
{myudt assign=years}{$yr=$smarty.now|date_format:'%Y'}
<select name="{$entry->id}" id="{$entry->id}">
{html_options options=$years selected=$yr}
</select>
{/if}
...Follow me on twitter
Please post system information from "Extensions >> System Information" (there is a bbcode option) on all posts asking for assistance.
--------------------
If you can't bother explaining your problem well, you shouldn't expect much in the way of assistance.
Please post system information from "Extensions >> System Information" (there is a bbcode option) on all posts asking for assistance.
--------------------
If you can't bother explaining your problem well, you shouldn't expect much in the way of assistance.



