Page 1 of 1
FormBuilder Fieldset attribute and smarty variables
Posted: Tue Apr 24, 2007 1:49 am
by JohnnyB
What variables are available when using the fieldset start and fieldset end fields in FormBuilder?
For example, how can I control the positioning and html output for the fieldset and legend tags generated? I create my own custom css, list based forms and I can't seem to get the fieldset outside of the list....
thanks in advance for any suggestions.
EDIT: here's an example of what I'm my custom template
{$hidden}
{foreach from=$fields item=entry}
{if $entry->display == 1}
{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}
input_id}">{$entry->name}
{if $entry->required_symbol != ''}
{$entry->required_symbol}
{/if}
{/if}
{if $entry->multiple_parts == 1}
{foreach from=$entry->input item=part}
{$part->input} {$part->name}
{/foreach}
{else}
{$entry->input}
{/if}
{if $entry->valid == 0} <--- {/if}
{/strip}
{/if}
{/foreach}
{$submit}
This results in a form that looks like this (HTML excerpt):
Your Information
First and Last Name*
Company Name
Website Address
And etc...
I'm trying to get the fieldset and legend (Marked in Bold above) outside of my list. I've tried as much as I know and I can't figure it out...

Re: FormBuilder Fieldset attribute and smarty variables
Posted: Tue Apr 24, 2007 2:48 am
by calguy1000
As it says in the template documentation: $field->type works:
Code: Select all
{literal}
<!-- below, you'll find the "standard CSS template" for displaying FormBuilder Forms
You can edit it to make your form layout look any way you'd like.
To make the form work, you'll need to always include the {$hidden} and {$submit}
tags.
You can access your form fields either using the $fields array, as demonstrated below,
or by directly accessing fields by their names (e.g., {$myfield->input} )
Each field has the following attributes:
field->display = 1 if the field should be displayed, 0 otherwise
field->required = 1 if the field is required, 0 otherwise
field->required_symbol = the symbol for required fields
field->css_class = the CSS class specified for this field
field->valid = 1 if this field has passed validation, 0 otherwise
field->hide_name = 1 if the field name should be hidden, 0 otherwise
field->name = the field's name
field->input = the field's input control (e.g., the input field itself)
field->input_id = the of the field's input (useful for <label for="">)
field->type = the field's data type
field->multiple_parts = 1 if the field->input is actually a collection of controls
In certain cases, field->input is actually an array of objects rather than an input. This
happens, for example, in CheckBoxGroups or RadioButtonGroups. For them, you
can iterate through field->input->name and field->input->inputs.
Additional smarty variables that you can use include:
{$total_pages} - number of pages for multi-page forms
{$this_page} - number fo the current page for multi-page forms
{$title_page_x_of_y} - displays "page x of y" for multi-page forms
{$css_class} - CSS Class for the form
{$form_name} - Form name
{$form_id} - Form Database ID
{$prev} - "Back" button for multipart forms
Dunno why you'd want some of those, but there you go...
-->
{/literal}
{$hidden}{assign var="cols" value="3"}
<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}
<!-- {$entry|print_r} -->
{if $entry->display == 1}
{strip}
{* leading div before the tag *}
{if $entry->type != "Fieldset Start" && $entry->type != "Fieldset End"}
<div
{if $entry->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}
{* begin field output *}
{if $entry->hide_name == 0}
<label for="{$entry->input_id}">{$entry->name}</label>
{if $entry->required_symbol != ''}
{$entry->required_symbol}
{/if}
{/if}
{if $entry->multiple_parts == 1}
<table>
<tr>
{section name=numloop loop=$entry->input}
<td>{$entry->input[numloop]->input} {$entry->input[numloop]->name}</td>
{if not ($smarty.section.numloop.rownum mod $cols)}
{if not $smarty.section.numloop.last}
</tr><tr>
{/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}
<td> </td>
{/section}
{/if}
</tr>
{/if}
{/section}
</table>
{else}
{$entry->input}
{/if}
{if $entry->valid == 0} <--- {/if}
{* trailing div *}
{if $entry->type != "Fieldset Start" && $entry->type != "Fieldset End"}
</div>
{/if}
{/strip}
{/if}
{/foreach}
<div class="submit">{$prev}{$submit}</div>
</div>
Re: FormBuilder Fieldset attribute and smarty variables
Posted: Wed Apr 25, 2007 12:05 am
by JohnnyB
Thanks.
I was using $entry->type.
I tried using $field->type but I guess I'm lost.
Is this the right way to us it?
Code: Select all
{if $field->type != "Fieldset Start" && $field->type != "Fieldset End"}
I've tried placing an if and/if in various places in my template but I'm not sure how to do it.
Re: FormBuilder Fieldset attribute and smarty variables
Posted: Wed Apr 25, 2007 1:23 am
by calguy1000
sorry, the docs are a bit out, but the example above works.
it's $entry->type