FormBuilder dropdown with data from LISE

Have a question or a suggestion about a 3rd party addon module or plugin?
Let us know here.
johnboyuk1
Forum Members
Forum Members
Posts: 235
Joined: Mon Nov 26, 2018 3:09 pm

FormBuilder dropdown with data from LISE

Post by johnboyuk1 »

Hi all... I'm struggling to work this out - its beyond my skill level!

I'd like to create a form in FormBuilder that contains a dropdown selector that's populated by data from a LISE module. Essentially I want to be able to populate sector with a list of the item titles from Lise.

I can see there's a 'Module Interface' and a 'UDT call' option in FormBuilder but I've no idea on how to use. Has anyone done anything similar that they wouldn't mind sharing the method / code for?

Many thanks
User avatar
Jo Morg
Dev Team Member
Dev Team Member
Posts: 1978
Joined: Mon Jan 29, 2007 4:47 pm

Re: FormBuilder dropdown with data from LISE

Post by Jo Morg »

Depending on how you build your template...
I always use HTML in templates so that I can use smarty at will to build complex forms. For instance I would use a normal text input field in FB field list and in the template do something like:

Code: Select all

{LISE_instance_name assign = junk}
<select class="form-control required"  title="Select Item" name="{$actionid}{$field_alias->input_id}" id="whatever">
 <option value="">Select items</option>
  {foreach $items as $item}
    <option value="{$item->alias}">{$item->title}</option>
  {/foreach}
</select>
Note: in {$field_alias->input_id} replace field_alias with the alias assigned to the FB field.

This is how I would do the LISE list dropdown. I am assuming that you make your own templates rather than use the default ones.
"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!
johnboyuk1
Forum Members
Forum Members
Posts: 235
Joined: Mon Nov 26, 2018 3:09 pm

Re: FormBuilder dropdown with data from LISE

Post by johnboyuk1 »

This is great - thanks Jo.

I dont normally build my own FB templates as I only normally use it for simple contact forms - I'll happily modify a default one to put this code in though! ;)
johnboyuk1
Forum Members
Forum Members
Posts: 235
Joined: Mon Nov 26, 2018 3:09 pm

Re: FormBuilder dropdown with data from LISE

Post by johnboyuk1 »

I've hit a problem! I'm using the 'Email results to set addresses' field in FormBuilder to email the results of the form, I've no idea how to get the data from the code you gave me (above) which I pasted into the template.

Can you help?

So all I did with the code you gave me was paste it into the form builder template, not sure if I was supposed to do anything else?

Many thanks
User avatar
velden
Dev Team Member
Dev Team Member
Posts: 3497
Joined: Mon Nov 28, 2011 9:29 am

Re: FormBuilder dropdown with data from LISE

Post by velden »

For instance I would use a normal text input field in FB field list and in the template do something like:
If you're building a custom dropdown list for Formbuilder (using LISE) the input can't be easily validated by FormBuilder.

Can you imagine what an evil visitor of the form will be able to do when you're allowing just any value for the 'Email results to set addresses' field?
Probably you don't want that to happen.

From the help:
*Email Results to set Address(es). This simply sends the form results to one or more email addresses that you enter when you create or edit this type of field. This field and its name are not visible in the form that the user sees. The email addresses are not made visible nor are they embedded in the HTML.

*Email results based on frontend fields. This field is an email disposition that allows form fields' user input to specify the Email Subject, "From Name", "From Address", and Destination Email Address.

*Email to User-Supplied Address. This puts an input field in the form for the user to populate with an email address. The form results get sent to that address. Beware of Spam abuse! Active the primitive anti-spam features in the FormBuilder configuration screen.
johnboyuk1
Forum Members
Forum Members
Posts: 235
Joined: Mon Nov 26, 2018 3:09 pm

Re: FormBuilder dropdown with data from LISE

Post by johnboyuk1 »

Thanks Velden, not sure I'm being clear.. I'm not populating the email fieldform with values, here's what I'm trying to do in simple terms...

• I have a LISEmodule that is a list of events

• I want to create a contact form which features a dropdown menu that pulls in this list of events so that when somebody makes contact they can select which event they're contacting about


So what I have managed to achieve with Jo's code is to get a dropdown menu inserted into the FormBuilder template that does indeed list the events as required

What I'm having trouble doing is getting that fields value to submit as part of the 'Email to user' function. That function in FormBuilder is a HTML email template which you can output FB fields into - eg {$fld_18}. Because the dropdown was manually coded into the form template there's no variable created for it by FB

I'm not sure I'm explaining it well/with the correct terminology! Hopefully you can unpick what I mean!

Thanks ;)
User avatar
velden
Dev Team Member
Dev Team Member
Posts: 3497
Joined: Mon Nov 28, 2011 9:29 am

Re: FormBuilder dropdown with data from LISE

Post by velden »

Ok, think I understand it now.

Again I think you should carefully read JoMorg's post.
For instance I would use a normal text input field in FB field list and in the template do something like:
If you do that, you should make sure that field is populated with the values you want.

He explained it in his sample code. You can't just add a form field to the template only, it must exist in the list of FormBuilder fields for your form to be processed.

Then in your email template you will be able to reference this 'normal text input field' (which has an alias an id because it's in the list of fields).
johnboyuk1
Forum Members
Forum Members
Posts: 235
Joined: Mon Nov 26, 2018 3:09 pm

Re: FormBuilder dropdown with data from LISE

Post by johnboyuk1 »

Thanks - I'm clearly not grasping this / doing it wrong somewhere... here's what I have done

1. Created a text input field which I have called 'test_field'
2. Pasted Jo's code on the template changing {$field_alias->input_id} to {$test_field->input_id}

I still dont get a value come through on the email though? Here's the full template code, maybe I've put Jo's coed in the wrong place?

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="error_message">
		<ul>
		{foreach from=$fb_form_validation_errors item=thisErr}
			<li>{$thisErr}</li>
		{/foreach}
		</ul>
		</div>
	{/if}
	{if isset($captcha_error) && $captcha_error}
		<div class="error_message">{$captcha_error}</div>
	{/if}

	{* and now the form itself *}
	{$fb_form_start}

{LISECourses assign = junk}
<select class="form-control required"  title="Select Item" name="{$actionid}{$test_field->input_id}" id="whatever">
 <option value="">Select items</option>
  {foreach $items as $item}
    <option value="{$item->alias}">{$item->title}</option>
  {/foreach}
</select>


	<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 != ''}
					{$entry->required_symbol}
				{/if}
				</label>
			{/if}
			{if $entry->multiple_parts == 1}
				{section name=numloop loop=$entry->input}
					{if $entry->label_parts == 1}
						<div>{$entry->input[numloop]->input}&nbsp;{$entry->input[numloop]->name}</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}{$entry->input}{/if}
			{/if}
			{if $entry->helptext != ''}&nbsp;<a href="javascript:fbht('{$entry->field_helptext_id}')"><img src="modules/FormBuilder/images/info-small.gif" alt="Help" /></a>
					<span id="{$entry->field_helptext_id}" style="display:none" class="fbr_helptext">{$entry->helptext}</span>{/if}
			{if $entry->valid == 0} <--- {$entry->error}{/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">{$prev}{$submit}</div>
	</div>
	{$fb_form_end}
{/if}
{$fb_form_footer}
User avatar
velden
Dev Team Member
Dev Team Member
Posts: 3497
Joined: Mon Nov 28, 2011 9:29 am

Re: FormBuilder dropdown with data from LISE

Post by velden »

And what about the email template?

Can you post it too?

Did you update that template after adding test_field to the list of fields?
johnboyuk1
Forum Members
Forum Members
Posts: 235
Joined: Mon Nov 26, 2018 3:09 pm

Re: FormBuilder dropdown with data from LISE

Post by johnboyuk1 »

yep, so the email template just says

Code: Select all

<h1>FormBuilder Submission</h1>

<hr />
{$test_field}
So at the moment the form when output on page shows a dropdown, plus a text input box (which is the test_field input), which I assume I would have to hide, and a submit button

Obviously if I enter a value in the test_field box it comes through via the email, but is not populating with the value from the dropdown
User avatar
velden
Dev Team Member
Dev Team Member
Posts: 3497
Joined: Mon Nov 28, 2011 9:29 am

Re: FormBuilder dropdown with data from LISE

Post by velden »

Of course, you shouldn't be using the sample form template anymore.

You should NOT hide the input text field, it shouldn't be present twice in the form.

Either remove this part (code below) and add the fields in de template manually or make sure if the field alias matches your custom field it's skipped.

Code: Select all

  {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 != ''}
               {$entry->required_symbol}
            {/if}
            </label>
         {/if}
         {if $entry->multiple_parts == 1}
            {section name=numloop loop=$entry->input}
               {if $entry->label_parts == 1}
                  <div>{$entry->input[numloop]->input}&nbsp;{$entry->input[numloop]->name}</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}{$entry->input}{/if}
         {/if}
         {if $entry->helptext != ''}&nbsp;<a href="javascript:fbht('{$entry->field_helptext_id}')"><img src="modules/FormBuilder/images/info-small.gif" alt="Help" /></a>
               <span id="{$entry->field_helptext_id}" style="display:none" class="fbr_helptext">{$entry->helptext}</span>{/if}
         {if $entry->valid == 0} <--- {$entry->error}{/if}
         {if $entry->needs_div == 1}
            </div>
         {/if}
         {/strip}
      {/if}
   {/foreach}
Especially because the input field comes after the dropdown I can imagine it overrides the value chosen from the dropdown.
johnboyuk1
Forum Members
Forum Members
Posts: 235
Joined: Mon Nov 26, 2018 3:09 pm

Re: FormBuilder dropdown with data from LISE

Post by johnboyuk1 »

ok , really appreciate you taking the time to talk me through this, I am obviously still being dumb somewhere though! I've now got this as the template:

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="error_message">
		<ul>
		{foreach from=$fb_form_validation_errors item=thisErr}
			<li>{$thisErr}</li>
		{/foreach}
		</ul>
		</div>
	{/if}
	{if isset($captcha_error) && $captcha_error}
		<div class="error_message">{$captcha_error}</div>
	{/if}

	{* and now the form itself *}
	{$fb_form_start}

{LISECourses assign = junk}
<select class="form-control required"  title="Select Item" name="{$actionid}{$test_field->input_id}" id="test-field">
 <option value="">Select items</option>
  {foreach $items as $item}
    <option value="{$item->alias}">{$item->title}</option>
  {/foreach}
</select>


	<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}

	{if isset($has_captcha) && $has_captcha == 1}
		<div class="captcha">{$graphic_captcha}{$title_captcha}<br />{$input_captcha}</div>
	{/if}
	<div class="submit">{$prev}{$submit}</div>
	</div>
	{$fb_form_end}
{/if}
{$fb_form_footer}
And I have 2 fields set up in Form Builder - one a text input called 'test_field' and the other an "email results to...' field

When I run the form though the email comes through with that test_field value as [unspecified]
User avatar
Dr.CSS
Moderator
Moderator
Posts: 12711
Joined: Thu Mar 09, 2006 5:32 am

Re: FormBuilder dropdown with data from LISE

Post by Dr.CSS »

When you hit the "make an email template" button it generates field IDs like {$fld_18} it then pulls the info from that field which should be in your email template some where...

From sample...

{$modules_you_ll_be_using} / {$fld_13} Modules you'll be using together
{$what_will_you} / {$fld_14} What will you personally be doing on your CMS MS site?
{$where_are_you_from_} / {$fld_15} Where are you from?
{$do_you_have_any} / {$fld_16} Do you have any comments / feedback for me?

Yet another way of accessing field values is via $fieldname_obj, $alias_obj, or $fld_#_obj, where each field is an object containing:
name Field Name
type Field Type
id Internal Field ID
value Human-readable Value
valueArray Array of field value(s)
e.g., you could use "{$fld_1_obj->name} = {$fld_1_obj->value}
Alternate field names can be used interchangeably (especially useful if Smarty is choking on characters outside of ASCII 32-126).
Other fields will be available as you add them to the form.
johnboyuk1
Forum Members
Forum Members
Posts: 235
Joined: Mon Nov 26, 2018 3:09 pm

Re: FormBuilder dropdown with data from LISE

Post by johnboyuk1 »

Hi

Yes, I am calling the field within the email send - happens to be {$fld_36} - but that field is showing as undefined. The value is obviously not being passed from my custom select field into this formbuilder text input field. To outline what I've done so far...

1. Created a new Formbuilder template as outlined by Jo/Velden above that creates a select field from LISE titles
2. Created a 'Text input' Field in Formbuilder using the standard 'Add new field' method. Given this input the same name as the manually created select field mentioned above

What I had assumed the above would do is to populate the FB text field with the data from the select field so that it can be read as a formbuilder variable in the email creation template

This is based on the guidance given in the replies above - so I've probably not understood it properly ...if anyone can clarify for me I'd be grateful!
User avatar
Jo Morg
Dev Team Member
Dev Team Member
Posts: 1978
Joined: Mon Jan 29, 2007 4:47 pm

Re: FormBuilder dropdown with data from LISE

Post by Jo Morg »

johnboyuk1 wrote:Yes, I am calling the field within the email send - happens to be {$fld_36} - but that field is showing as undefined. The value is obviously not being passed from my custom select field into this formbuilder text input field. To outline what I've done so far...
Try the following:
- where you have

Code: Select all

{LISECourses assign = junk}
<select class="form-control required"  title="Select Item" name="{$actionid}{$test_field->input_id}" id="test-field">
 <option value="">Select items</option>
  {foreach $items as $item}
    <option value="{$item->alias}">{$item->title}</option>
  {/foreach}
</select>
replace with

Code: Select all

{LISECourses assign = junk}
<select class="form-control required"  title="Select Item" name="{$actionid}{$fld_36->input_id}" id="test-field">
 <option value="">Select items</option>
  {foreach $items as $item}
    <option value="{$item->alias}">{$item->title}</option>
  {/foreach}
</select>
"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!
Post Reply

Return to “Modules/Add-Ons”