Passing Default values to FormBuilder Multiselect Topic is solved

Have a question or a suggestion about a 3rd party addon module or plugin?
Let us know here.
Post Reply
webform
Power Poster
Power Poster
Posts: 460
Joined: Sat Nov 25, 2006 3:39 pm
Location: Copenhagen, Denmark

Passing Default values to FormBuilder Multiselect

Post by webform »

I'm trying to pass default values to a FormBuilder Multiselect field and it works just fine with a single value but not with multiple values.

Code: Select all

{FormBuilder form='MyForm' value_TITLEFIELD='My Title' value_MULTISELECTFIELD='value1,value,2,value3'}
The help says "It may not work for more exotic field types". So the question is if Multiselect is one of the exotic field types and won't work?
User avatar
Dr.CSS
Moderator
Moderator
Posts: 12709
Joined: Thu Mar 09, 2006 5:32 am
Location: Arizona

Re: Passing Default values to FormBuilder Multiselect

Post by Dr.CSS »

You may want to look at the form in html and see if your fields are in uppercase or did you fill them in that way...
webform
Power Poster
Power Poster
Posts: 460
Joined: Sat Nov 25, 2006 3:39 pm
Location: Copenhagen, Denmark

Re: Passing Default values to FormBuilder Multiselect

Post by webform »

I use the fields ID to pass default values like value_fld12='value1,value,2,value3', where the field is a Multiselect Field Type.

And default value IS passed if there is only one value but not if there is multiple values, like in the example above. So it may not work to pass multiple values to a Multiselect Field?
User avatar
DIGI3
Dev Team Member
Dev Team Member
Posts: 1629
Joined: Wed Feb 25, 2009 4:25 am
Location: Victoria, BC

Re: Passing Default values to FormBuilder Multiselect

Post by DIGI3 »

It's possible it doesn't handle that properly for multiselects when using the default template (the help specifically says it's for fields with a single value), but if you can confirm it's actually passing in all the values as a csv you should be able to create the field manually instead of using $entry->input or whatever. The module help has some details under "Templates and Variables".
Not getting the answer you need? CMSMS support options
webform
Power Poster
Power Poster
Posts: 460
Joined: Sat Nov 25, 2006 3:39 pm
Location: Copenhagen, Denmark

Re: Passing Default values to FormBuilder Multiselect

Post by webform »

Yeah, i need to take my thinking hat on and look into if i could recreate the multiselect field manually in the form template, so i can preselect the multiselect values i need :-\
User avatar
Jo Morg
Dev Team Member
Dev Team Member
Posts: 1924
Joined: Mon Jan 29, 2007 4:47 pm

Re: Passing Default values to FormBuilder Multiselect

Post by Jo Morg »

if you move away from the form samples (which are there more as generic all purpose templates to make sure the module can be used out of the box) you can do whatever you need, the mantra being to use pure HTML and the provided variables, so that a text input would be something like:

Code: Select all

<input
  type="text"
  name="{$actionid}{$myfield->input_id}"
  value="{$myfield->value}"
  id="{$myfield->name}"
  class="whatever-class-you-want"
>


where $myfield is the name or alias of the field...
again, in the case of a text input:

Code: Select all

<input
  type="text"
  name="{$actionid}{$myfield->input_id}"
  value="{$myfield->value|default:'my default value'}"
  id="{$myfield->name}"
  class="whatever-class-you-want"
>"
You can port this logic to any type of field including multi-select where you can even use the smarty plugins available to set them up for you. such as {html_options}
"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!
webform
Power Poster
Power Poster
Posts: 460
Joined: Sat Nov 25, 2006 3:39 pm
Location: Copenhagen, Denmark

Re: Passing Default values to FormBuilder Multiselect

Post by webform »

Normally I use the default template, where I adapt it to be usable with Bootstrap.
And it works fantastic in most cases, but in this case I will probably have to make a custom html template as you suggest, so that I can get many select values into a multiselect field. (I'm building a frontend editing form for a LISE instance).

Thanks for the suggestions!

Here is my "normal" form template adapted to Bootstrap:

Code: Select all

{* DEFAULT FORM LAYOUT / pure CSS *}
{literal}
<__script__ type="text/javascript">
function fbht(htid)
	{
		var fbhtc=document.getElementById(htid);
		if (fbhtc)
			{
			if (fbhtc.style.display == 'none')
				{
				fbhtc.style.display = 'inline';
				}
			else
				{
				fbhtc.style.display = 'none';
				}
			}
}
</__script>
{/literal}

{$fb_form_header}
{if $fb_form_done == 1}
	{* This first section is for displaying submission errors *}
	{if isset($fb_submission_error) && $fb_submission_error}
		<div class="error_message">{$fb_submission_error}</div>
		{if isset($fb_show_submission_errors) && $fb_show_submission_errors}
			<div class="error">
			<ul>
			{foreach from=$fb_submission_error_list item=thisErr}
				<li>{$thisErr}</li>
			{/foreach}
			</ul>
		</div>
		{/if}
	{/if}
{else}
	{* this section is for displaying the form *}
	{* we start with validation errors *}
	{if isset($fb_form_has_validation_errors) && $fb_form_has_validation_errors}
	<div class="style-msg2 errormsg">
		<div class="msgtitle">Fix the Following Errors:</div>
		<div class="sb-msg">
			<ul>
			{foreach from=$fb_form_validation_errors item=thisErr}
				<li>{$thisErr}</li>
			{/foreach}
			</ul>
		</div>
	</div>
	{/if}
	{if isset($captcha_error) && $captcha_error}
		<div class="error_message">{$captcha_error}</div>
	{/if}

	{* and now the form itself *}
	{$fb_form_start}
	<div>{$fb_hidden}</div>
	<div{if $css_class != ''} class="{$css_class}"{/if}>
	{if $total_pages gt 1}<span>{$title_page_x_of_y}</span>{/if}
	{foreach from=$fields item=entry}
		{if $entry->display == 1}
			{strip}
			{if $entry->needs_div == 1}
				<div
				{if $entry->required == 1 || $entry->css_class != '' || $entry->valid == 0} class="
					{if $entry->required == 1}required{/if}
					{if $entry->css_class != ''} {$entry->css_class}{/if}
					{if $entry->valid == 0} fb_invalid{/if}
					"
				{/if}
				>
			{/if}
			{if $entry->hide_name == 0}
				<label{if $entry->multiple_parts != 1} for="{$entry->input_id}"{/if}>{$entry->name}
				{if $entry->required_symbol != ''}
					<span class="text-danger">{$entry->required_symbol}</span>
				{/if}
				</label>
			{/if}
			{if $entry->multiple_parts == 1}
				{section name=numloop loop=$entry->input}
					{if $entry->label_parts == 1}
						<div class="form-check">
							{if $entry->type == 'Check Box Group'}{$entry->input[numloop]->input|replace:'class="cms_checkbox':'class="form-check-input'}
							{elseif $entry->type == 'Radio Button Group'}{$entry->input[numloop]->input|replace:'id=':'class="form-check-input" id='}
							{else}{$entry->input[numloop]->input}
							{/if}
							&nbsp;{$entry->input[numloop]->name|replace:'<label':'<label class="form-check-label" '}
						</div>
					{else}
						{$entry->input[numloop]->input}
					{/if}
					{if isset($entry->input[numloop]->op) && $entry->input[numloop]->op}{$entry->input[numloop]->op}{/if}
				{/section}
			{else}
				{if $entry->smarty_eval == '1'}{eval var=$entry->input}{else}
				{if $entry->type == 'Text Area'}{$entry->input|replace:'class="cms_textarea':'class="form-control'}
				{elseif $entry->type == 'Pulldown'}{$entry->input|replace:'class="cms_dropdown':'class="form-select'}
				{elseif $entry->type == 'Multiselect'}{$entry->input|replace:'class="cms_select':'class="form-select'}
				{elseif $entry->type == 'File Upload'}<div class="form-file">{$entry->input|replace:'class="cms_browse':'class="form-control'}</div>
				{elseif $entry->type == 'Check Box'}<div class="form-check">{$entry->input|replace:'class="cms_checkbox':'class="form-check-input'|replace:'<label':'<label class="form-check-label" '}</div>
				{elseif $entry->type == '-Fieldset Start' || $entry->type == '-Fieldset End'}{$entry->input|replace:'fieldset':'div'}
				{else}{$entry->input|replace:'id=':'class="form-control" id='}
				{/if}
				{/if}
			{/if}
			{if $entry->valid == 0}<small class="form-text text-danger d-block"> &lt;--- {$entry->error}</small>{/if}
			{if $entry->helptext != ''}<small id="{$entry->field_helptext_id}" class="form-text text-muted">{$entry->helptext}</small>{/if}
			{if $entry->needs_div == 1}
				</div>
			{/if}
			{/strip}
		{/if}
	{/foreach}
	{if isset($has_captcha) && $has_captcha == 1}
		<div class="captcha">{$graphic_captcha}{$title_captcha}<br />{$input_captcha}</div>
	{/if}
	<div class="submit">{$submit|replace:'class="':'class="button button-large button-dark rounded m-0 '}</div>
	</div>
	{$fb_form_end}
{/if}
{$fb_form_footer}
webform
Power Poster
Power Poster
Posts: 460
Joined: Sat Nov 25, 2006 3:39 pm
Location: Copenhagen, Denmark

Re: Passing Default values to FormBuilder Multiselect

Post by webform »

After thinking about it a bit more, I have managed to pass an array of values to a multiselect field in FormBuilder.
I converted my selected values to an array and then FormBuilder wanted to accept the data.

Code: Select all

{$title = $item->title}
{assign var='category' value=','|explode:"{$item->category}"}
{FormBuilder form='edit_lesson' value_fld120=$title value_fld121=$category}
Post Reply

Return to “Modules/Add-Ons”