Home > Form Elements > E-Commerce
In Brief: A form element for setting properties for a "product", which combined with an e-comm confirmation page element, can be used to sell items using the proper transaction agent.
Dependencies: A standard form page.
Hints & Tricks: You can switch payment processors at any time, but be aware that each payment agent may require slightly different fields to process the transaction correctly.
In order to process an e-comm item, you also need to create an e-comm confirmation page element. In other words, each e-commerce field item needs a corresponding e-commerce confirmation page element!
Starting with Build 693 it is now easier to create Shopping Cart like applications within FormBoss. This is in part possible because the Label field now supports tokens, as well as a sample job being created to show some tricks located at:
\formboss\goodies\Sample Jobs\E-Commerce\basic-shopping-cart.xml
Using this job as a guide should give you a good handle on what's needed to create your own shopping cart solution.
Options/Properties
Basic Attributes
Label
Type the text you want to appear above or to the side of the form element. This is also the value of the text displayed in the FormBoss Result Browser and Email messages.
The label field supports local PHP variables if they are wrapped in PHP tags and echo'd out as: <?php echo $val; ?>
Please note that only local variables are supported, $_SESSION variables must be bound to local variables in the PHP Top Code or PHP Head Code section first.
As of Build 693 the functionality of this item has been expanded to support dynamic tokens for E-Commerce items. Please see the in-editor tooltip (located just above this field), for specifics.
As of Build 701, this field now also accepts the standard FormBoss 2 token set for form field labels. Please see the in-app tooltip for exact values to use.
As of Build 705, this field now accepts the standard FormBoss 2 token set for Section/Headline Text and Body Copy elements. That is, we used to only be able to use the @{value} token, as can now use F{}, S{} and so on.
The 'new' tokens will, by default, transform linebreaks into HTML br tags. This is very handy when we want to display a text area to a user where such line breaks have been added. This ensures the typed value matches, as closely as possible, the display.
Also in Build 705 is the 'raw' field token: FR{field_name}. This token was created because by default, when we use a F{} token for say, text1, we are actually creating the following code:
<?php if(isset($_SESSION['qs']["{$_SESSION['entry_key']}"]['text1'])) { echo "{$_SESSION['qs']["{$_SESSION['entry_key']}"]['text1']}"; }?>
That is, a full (but inline) PHP block. This makes it impossible to create custom logic in a Body Copy or Section Text block, as the open and close PHP blocks break any such custom code.
Thus, the raw token only places the raw field value into the text data, nothing more. The same text1 item now looks like:
$_SESSION['qs']["{$_SESSION['entry_key']}"]['text1']
That is, no PHP block, and no isset().This means we could, for example, create the following logic in a Body Copy element:
<?php
if(isset(FR{text1}) && FR{text1} != "") { ?>
I want to hide this Bodycopy if @{text1} is empty ?
<?php } ?>
Name/Value
This element is set by FormBoss automatically, though it is recommended to change this value if you decide to display Javascript validation messages, as the 'identifying' text of the error is the value of this field.
This value is displayed by default if no 'Label' attribute is assigned to the element. For technical users, this element name is in fact the same as the Name/Value html form attribute of this element.
You will also notice that if you change the name of this field, the id attribute to the immediate right of this element also updates with the same value. This is because in most cases you should keep the same value for both elements--however, you can use a different value, simply type in the id field separately.
Naming Convention Note: The only valid punctuation for the Name/Value and id fields is the underscore _. Use of any other character will cause the form to fail.
id
By default is assigned the same value as the Name/Value element, though you can change this to a more field specific value. Not necessary for most applications. For technical users, this is the id attribute of the field item.
Helper Text
This text displays on the bottom of the field item. By default, the text is 7pt and light grey #888888. You can change the elements color in the FormBoss editor, but the font size must be changed in the jobs formpage.css file.
Default Value
[Only used with text element such as text box and text area]
Any pre-assigned values for this element should be typed into this box. At run-time this value is automatically populated into the field item.
You can use PHP variable names in this field, simply include the variable name enclosed in braces as in: {$random_variable}
There are a few special considerations with using PHP variables in this field:
1. Always wrap the full variable in braces.
2. You cannot execute functions in this block, only variables.
3. $_SESSION variables must use single quotes as in {$_SESSION['variable']}, not double quotes as in {$_SESSION["variable"]}
4. All variables are passed through htmlentities($variable, ENT_COMPAT), which means any double quotes are turned into "
Field Width
In pixels units, the height of the field item. Default of 140 for text boxes and 200 for text areas.
Field Height
In pixels, the width of the field item. Default of 70.
TinyMCE Editor
[Text area only]
Adds a TinyMCE Rich Text Editor to the text area.
Select from three TinyMCE preset configurations:
Simple Editor - Provides basic text controls.
Text Heavy - Provides ~13 text editing tools plus a slew of editing control such as undo.
FromBoss Style - Creates the same suit of text editing tools used in the FormBoss Editor.
* Please be aware that at this time the Display Field Count validation property has no effect on text areas that use TinyMCE. You can still set a maximum character count, but this value will only be validated at the time of the forms submission via PHP, not JavaScript.
** You can only use 1 style of TinyMCE text editor per form page. The text area that comes first in the form will determine which TinyMCE text editor configuration is used.
Wrapper Class Name
Every field element in FormBoss is wrapped in either a LI or DIV element for Sortable or Free Form page types, respectively. When you place a value in this box it becomes the class="" attribute for that wrapper. Because a wrapper encompass both the input element and wrapper, you can use this value to show and hide sections of your form.
Extra Attribute(s) JS Etc - Formerly known as [ Extra Attribute(s) JS Style Etc ]
Although similar to a submit button, a button has an html type of 'button', not type=submit, which means when this element is clicked on,
your form will not be submitted, but rather you must supply the event to occur.
A common use of this type of element would be to attach a history command such as onclick="history.back()", and then use it on a multi-form page to make navigating back one page easier than using text links.
Add code to your field item by typing it into this box. Code can be JavaScript event code such as:
onclick="alert('Be sure to use Letters only');"
External Library dependent code as in: (Prototype/Scriptaculous example)
onclick="Effect.Fade(this, { duration:.2});"
What's important to note is that the code you create here effects the field element, not the container it sits in. To edit the field container, you need to reference the field name prefixed with 'fb_fld-', as in a text box with an ID of text1 would be referenced like:
fb_fld-text1
Extra Input Field Style Attributes
New to Build 683, this field allows us to define extra style attributes for our form elements such as:
Or Style definitions as in:
style="color:#cdcdcd;"
It is important to note that in older versions of FormBoss we would have applied styles to the Extra Attribute(s) JS Etc field.
Finally, it is also important to consider that FormBoss also applies style data, traditionally as:
font-size:12px; color:#444444; font-family:inherit; width:200px; height:70px;
In short, font properties and height/width are handled automatically via editor properties.
Conditional Processing
Field Initially Visible?
Determines if the form element is visible when the page first loads. Please note that this logic always resets on page load, that is, if a user goes back one page where an element was previously shown it will be invisible again.
Easy Toggle?
Checking this box means FormBoss will automatically handle the logic needed to perform the opposite action you set in Then... and If This Field Is: properties. For example, if you set the action of an item to be 'Show', if the condition needed to make this show acton happen is revoked, the opposite action will automatically happen for you. So, if the condition is the text '1' must be set in a text box in order to show a second text field, if this 1 is removed or changed, the second text box will be hidden again.
In general we want to keep this box checked, though if you wanted to force a field to always show after an action then leave it unchecked.
Event Trigger
This is the JavaScript event that will be scanned for and then acted upon if activated. Some events are better than others for the various tasks you have. For example, the onClick event is perfect for Checkboxes, whereas the onKeyUp event is perfect for text boxes where a user needs to enter a specific value. Experiment with these values and have fun!
Caution! You may run into a situation where you build a form that enables the event trigger on a specific field, then remove that field later on without updating the Event Trigger's 'binding' to that element.
If this happens your forms validation will break, along with other potential issues.
The solution is always make sure that when we enable an event trigger for an element, that field exists on the form.
Animation?
While not always needed, if you want you can add animation using Prototype JS to your events. The upside of this is your forms may have a more professional appearance, the downside is the extra bandwidth needed to send the Prototype JS library over the wire to run the animations. However, if you are already using animation or have included the Prototype JS library for other purposes, this bandwidth cost is obviously negated, so animate away!
If This Field Is:
This is the core property of the Conditional Processing logic. In most cases you will only want to show and hide fields if a specific condition is met, this option allows us to set that condition. As with the Event Trigger property, some options only make sense in the proper context. For example, the top Value Comparison grouping is best served in combination with text and select fields, whereas the Field State options of Checked and Unchecked only make sense for checkboxes.
It is also important to note that FormBoss will attempt to cast comparison values set as INT and FLOAT values to their respective native types.
This Value...
When we set the If This Field is property, with the exception of the two Field State checks of Checked and unchecked, we typically want to compare against some value. It is in this text box that we set that comparison value. FormBoss will automatically attempt to detect FLOAT and INT values when testing against GREATER THAN and LESS THAN checks.
Then:
If the condition set in If This Field Is and This Value... passes, this is the action we will perform. Please note that is Easy Toggle? is enabled, we will automatically perform the opposite when the check fails.
This Field Or...
When we set an event, comparison, and action, the last step is to tell FormBoss which fields to act upon. It is in this field and is close relative, This Wrapper Class, that we set this field or fields.
As you build your form FormBoss will automatically track the Name/Value properties of the elements on that form page and then present them to you in list format in this field. Thus, all eligible form fields will be displayed in this select item, the one you select will become the field acted upon.
Finally, any elements that are set to hidden on page load are tagged with a [H], which makes it easy in many cases to see which items you may need to work with.
This Wrapper Class
Similar to the This Field Or... property, with the exception that instead of single field we can act upon all elements with the same Wrapper Class attribute. This makes it very easy to show and hide large portions of content with one action, perfect for address fields and the like.
Custom Conditional Field Statement
Although FormBoss tires to automate as much of the show/hide process as possible, their will be times when you need to have more complex logic.
When this is the case, we can use the simple FormBoss API to create custom logic.
The bulk of this logic will be derived from a JavaScript object called fbc, which stands for FormBoss Conditional. This object is defined in:
/formboss-root/app/movefiles/conditional.js
Which is exported into the root of all FormBoss jobs.
The basic usage of this object will depend on what action you want to perform. That said, their are 4 methods you need to know about:
hideField, hideWrapper, showField, showWrapper
As shown in the editor, we call these methods as:
fbc.showField(event, 'FieldName', 'animation');
With a simple example to show a text box being:
if(value == '1'){
fbc.showField(event, 'text2'); // animation argument is optional, event is not!
}
Simple enough--But it is important to understand that at the page code level FormBoss creates two distinct but related items.
The first is the event trigger which is placed inline with your form element. Please be aware the event used is not created automatically, you need to select one from the Event Trigger select item.
Thus, if we select the onKeyUp event FormBoss will place this code inline with your element:
onkeyup="fb_dyn_text1(event, this.value, this)"
Notice we have three arguments. This is important because the inline method call is directlly tied to the second main element FormBoss creates for you, which is a script tag with that methods definition.
This method looks like:
function fb_dyn_text1(event, value, elt){
if(value == '1'){
fbc.showField(event, 'text2');
}
}
As you may now see, this method body is the code you create in the Custom Conditional Field Statement text area. The reason why it is wrapped in the method is to that you do not need to worry about creating or gathering the event, value, and elt parameters.
Thus, the last bit of knowlegde to convey is that these paramters, event, value, and elt, can be used in any way you need in your Custom Conditional Code. Most of the time you will only need the value parameter for your logic, but please notice you must pass event to the fbc functions no matter what.
Callbacks
New in Build 711, we now have a callback that's fired after an animation plays:
animationDone(elt)
We use this callback inline with our Conditional Code block as in:
fbc.animationDone = function(elt){
alert(elt.id);
// when animation is done, call resize function for iframe
window.parent.resizeSubForm(getOutputSize());
}
That is, we call fbc.animationDone(elt), then in that function, define the actions to take place.
The elt parameter is the object that called the animation, that is, is the object which reacted to the event.
Please note this event is fired for every animation that plays. Thus, if we've used this in the content of a Wrapper Class with say, 5 elements, this function is called 5 times.
Field Style Properties
Element z-index
New to Build 697, this feature allows us to set the z-index of most items. This property is reflected in the editor as well, making positioning items much more streamlines than in previous versions.
By default most items, with the exception of calendar fields, have a base index of 1. This means so long as your form fields to not overlap you will not need to set this property. However, some fields, such as images or those with popup's (like the calendar field), benefit from setting a different layering order.
Text Color
Click into the box to load the color selector. Drag your cursor over the saturation in the main box to select the color intensity, or drag the hue slider to change color.
Font Size(px)
Type a number in this box to change the font size of the element.
Label Font Weight
New to Build 685, this option lets us set the font weight of the forms field label or main text block.
Label Position
Has no effect for this field. Might be implemented in later versions.
E-Commerce Item Options
Transaction Type
Transaction type is the type of interaction we provide to the payment gateway.
The most basic distinction would be between say, a one time payment and a donation.
In FormBoss 2 We Can Choose From:
One Time Payment
Subscription
Donation
Shopping Cart Item
As a general rule, only PayPal supports the second, third and fourth options, though that could change in the future.
Setting this field tells FormBoss how to crate the payment gateway form, so make sure it is set correctly for the product you're setting up!
Thus, if you have a simple item you want to sell, you would select One Time Payment. If you want to allow your users to select more than one item and have FormBoss group them together on the PayPal payment page, select Shopping Cart Item.
Please note that when you select your Transaction Type you also need to be mindful of the Confirmation Pages' E-Commerce item options as well. This is because not all combinations will work. For example, as of right now only PayPal supports the Shopping Cart Item Transaction type.
A note on Shopping cart items
Shopping cart items are a special case in FormBoss that allow us to let the users select any number of items or products from the form page, then have PayPal batch them together into one lump payment item on the payment page. The limitation to this method is the items in PayPal are not itemized, but the benefit is that created a rather simple form of shopping cart.
The key point though is that in order for this shopping cart method to work we need to set the Transaction type to Shopping Cart Item in this field, and select Shopping Cart Items from the Process This Field... select item in the E-Commerce delivery module options.
A good way to learn about shopping cart items (for Builds 680 and higher) is to check out the sample job:
\formboss\goodies\Sample Jobs\E-Comm\paypal-shopping-cart.xml
Currency Type
Sets the currency type of the transaction. If you need a currency type added, please use the contact page to request one!
An important aspect of this field is we want to be sure to select the correct currency, not just the currency symbol. For example, The Australian Dollar and US dollars will not be processed the same by your e-commerce provider!
Transaction Language
Type in the name of the transaction language used. This is only applicable for PayPal, where you can find a full list of supported languages and countries here. Be sure to use the proper county code, which is, for PayPal, 2 letters.
Require Address?
If checked, the payment gateway will ask the user for their address on the checkout screen. Not needed for some transaction types, such as donations.
Form Field Type
New to Build 680 and expanded in Build 693,
this field allows us to set what he form field element will be. We can select from Radio, Checkbox, and Select items.
Please note that when we select checkbox items we are by default using the shopping cart method, as checkbox items mean that more than one item can be selected per purchase. As only shopping cart items support this method, the two items are complimentary.
Item Options
Price - The price of the transaction. Can be left blank for donations. Do not use punctuation other than a comma and/or decimal.
As of Build 651 this field is dynamic, we can use:
S{session_var_name} to include $_SESSION elements
F{field_item_name} to include Form Field Values.
Thus, we could let the user type in a donation amount on 1 page of your form, and that will be the value used for this element.
We could also create a more complex order form where we keep track of several elements and then create a 'total price' which is used again, as the value for the e-comm item, much like a traditional shopping cart.
Extra - Required for some gateways, for example 2Checkout requires this field to include the product_id of your item. Generally not used with PayPal and Google Checkout.
However, as of Build 699, we can now use this field to mark a PayPal shopping cart item as a discount item. We do so by applying a single (-) minus mark to the field.