[SOLVED] Form Builder: Populate field value with Smarty info?

Have a question or a suggestion about a 3rd party addon module or plugin?
Let us know here.
Locked
appleyard
Forum Members
Forum Members
Posts: 27
Joined: Wed Dec 30, 2009 2:54 pm

[SOLVED] Form Builder: Populate field value with Smarty info?

Post by appleyard »

I'm building a site where a contact form will be on every page, as part of the template. I was planning to make the "Subject" field automatically populate its initial value with the page title (e.g. [ value ="{title}" ]), but now I'm not sure how to do it. Form Builder doesn't seem to evaluate Smarty tags. Can anyone point me in the right direction? Much appreciated!
Last edited by appleyard on Tue May 18, 2010 7:29 pm, edited 1 time in total.
appleyard
Forum Members
Forum Members
Posts: 27
Joined: Wed Dec 30, 2009 2:54 pm

Re: Form Builder: Populate field value with Smarty info?

Post by appleyard »

Never mind, I figured it out. You can set default values for specific fields using the module parameters, e.g. {FormBuilder form='name' value_FIELDNAME='Default value'}

I just had to capture the info I wanted into a variable and use that. So to populate the Subject field with the title, I used:
{capture assign='formsubject'}Inquiry about {title}{/capture}{FormBuilder form='contact' value_Subject=$formsubject}
jgormont
New Member
New Member
Posts: 3
Joined: Thu May 20, 2010 8:24 pm

Re: [SOLVED] Form Builder: Populate field value with Smarty info?

Post by jgormont »

I'm having a similar issue actually. I'd like to set a default value in the Subject field of my form, but I'd like it to be static text, not based on the title. I'm new to CMS and Form Builder, so I'm not sure where to place to tag you provided in your last post. Should it go in the Form Template itself? If so, do you place it at the top or in the section with the subject field?

Here is my code, in case you need it:
{* TABLE FORM LAYOUT / Field titles on Left *}
{* next line sets number of columns for things like checkbox groups *}
{assign var="cols" value="3"}
{literal}

function fbht(htid)
{
var fbhtc=document.getElementById(htid);
if (fbhtc)
{
if (fbhtc.style.display == 'none')
{
fbhtc.style.display = 'inline';
}
else
{
fbhtc.style.display = 'none';
}
}
}

{/literal}
{$fb_form_header}
{if $fb_form_done == 1}
{* This first section is for displaying submission errors *}
{if $fb_submission_error}
{$fb_submission_error}
{if $fb_show_submission_errors}

{foreach from=$fb_submission_error_list item=thisErr}
{$thisErr}
{/foreach}

{/if}
{/if}
{else}
{* this section is for displaying the form *}
{* we start with validation errors *}
{if $fb_form_has_validation_errors}


{foreach from=$fb_form_validation_errors item=thisErr}
{$thisErr}
{/foreach}


{/if}
{if $captcha_error}
{$captcha_error}
{/if}

{* and now the form itself *}
The Jefferson County GIS/Addressing Office has data available at a map scale of 1:2400 in NAD 1983 StatePlane West Virginia North FIPS 4701 Feet. Layers are available in .gdb or .shp format, whole county only.
Each layer costs $84, not including media setup. Media setup and shipping & handling are $20 per media. For example: If ask for one layer to be mailed to you on a cd, the cost is $104.Once you have submitted this form, please download the Data Usage Agreement Form. This should be signed and mailed in with your payment. Orders will not be filled until the DUA Form and payment have been received.
{$fb_form_start}
{$fb_hidden}


{if $total_pages gt 1}{$title_page_x_of_y}{/if}
{foreach from=$fields item=entry}
{if $entry->display == 1 &&
$entry->type != '-Fieldset Start' &&
$entry->type != '-Fieldset End' }

{strip}
required == 1 || $entry->css_class != ''} class="
{if $entry->required == 1}
required
{/if}
{if $entry->required == 1 && $entry->css_class != ''} {/if}
{if $entry->css_class != ''}
{$entry->css_class}
{/if}
"
{/if}
>
{if $entry->hide_name == 0}
{$entry->name}
{if $entry->required_symbol != ''}
{$entry->required_symbol}
{/if}
{/if}
css_class != ''} class="{$entry->css_class}"{/if}>
{if $entry->multiple_parts == 1}


{section name=numloop loop=$entry->input}
{$entry->input[numloop]->input} {$entry->input[numloop]->name}{if $entry->input[numloop]->op} {$entry->input[numloop]->op}{/if}
{if not ($smarty.section.numloop.rownum mod $cols)}
{if not $smarty.section.numloop.last}

{/if}
{/if}
{if $smarty.section.numloop.last}
{math equation = "n - a % n" n=$cols a=$entry->input|@count assign="cells"}
{if $cells ne $cols}
{section name=pad loop=$cells}

 
{/section}
{/if}

{/if}
{/section}

{else}
{if $entry->smarty_eval == '1'}{eval var=$entry->input}{else}{$entry->input}{/if}
{/if}
{if $entry->valid == 0} <--- {$entry->error}{/if}
{if $entry->helptext != ''} field_helptext_id}')">
field_helptext_id}" style="display:none">{$entry->helptext}{/if}



{/strip}
{/if}
{/foreach}
{if $has_captcha == 1}
{$graphic_captcha}{$input_captcha}
{$title_captcha}
{/if}
{$prev}{$submit}

{$fb_form_end}
{/if}
{$fb_form_footer}
appleyard
Forum Members
Forum Members
Posts: 27
Joined: Wed Dec 30, 2009 2:54 pm

Re: [SOLVED] Form Builder: Populate field value with Smarty info?

Post by appleyard »

You don't need to modify the form template at all. You do it when you call the {FormBuilder} tag in your content. Just add value_FIELDNAME='DEFAULT VALUE' to that and replace the caps with your info. So, if the alias of your form is 'contact', the field you want to populate is labeled 'Subject', and the value you want to give it is 'Hello there', you would do something like this:
{FormBuilder form='contact' value_Subject='Hello there'}

Sometimes fields have labels that have punctuation or something that won't work in that format (e.g. "What's your question?") so you can use a unique field ID number instead. Find out the number that FormBuilder assigns to a field by checking "Show Field IDs" in the configuration tab, and just add that number after value_fld when you call the FormBuilder tag -- like this (for field ID = 5):
{FormBuilder form='contact' value_fld5='Hello there'}
appleyard
Forum Members
Forum Members
Posts: 27
Joined: Wed Dec 30, 2009 2:54 pm

Re: [SOLVED] Form Builder: Populate field value with Smarty info?

Post by appleyard »

Of course, that's if you want a field that the user will see and can be edited.

If you just want to edit what will show up in the actual subject line of the email when it's submitted, you would edit that in the "Email Subject Line" of the "Send To" / Email Results field.
jgormont
New Member
New Member
Posts: 3
Joined: Thu May 20, 2010 8:24 pm

Re: [SOLVED] Form Builder: Populate field value with Smarty info?

Post by jgormont »

I figured it out. Thanks!
Locked

Return to “Modules/Add-Ons”