Skip to content

View Helpers

checkBoxTag()

checkBoxTag() — returns string

Available in: controller Category: Form Tag Functions

Builds and returns a string containing a check box form control based on the supplied name. Note: Pass any additional arguments like class, rel, and id, and the generated tag will also include those values as HTML attributes.

NameTypeRequiredDefaultDescription
namestringyesName to populate in tag’s name attribute.
checkedbooleannofalseWhether or not the check box should be checked by default.
valuestringno1Value of check box in its checked state.
uncheckedValuestringnoThe value of the check box when it’s on the unchecked state.
labelstringnoThe label text to use in the form control.
labelPlacementstringnoaroundWhether to place the label before, after, or wrapped around the form control. Label text placement can be controlled using aroundLeft or aroundRight.
prependstringnoString to prepend to the form control. Useful to wrap the form control with HTML tags.
appendstringnoString to append to the form control. Useful to wrap the form control with HTML tags.
prependToLabelstringnoString to prepend to the form control’s label. Useful to wrap the form control with HTML tags.
appendToLabelstringnoString to append to the form control’s label. Useful to wrap the form control with HTML tags.
encodeanynotrueUse this argument to decide whether the output of the function should be encoded in order to prevent Cross Site Scripting (XSS) attacks. Set it to true to encode all relevant output for the specific HTML element in question (e.g. tag content, attribute values, and URLs). For HTML elements that have both tag content and attribute values you can set this argument to attributes to only encode attribute values and not tag content.
1. Basic checkbox
#checkBoxTag(name="subscribe", value="true", label="Subscribe to our newsletter", checked=false)#

2. Checkboxes generated from a query
// Controller code
pizza = model("pizza").findByKey(session.pizzaId);
selectedToppings = pizza.toppings();
toppings = model("topping").findAll(order="name");

<!--- View code --->
<fieldset>
	<legend>Toppings</legend>
	<cfoutput query="toppings">
		#checkBoxTag(name="toppings", value="true", label=toppings.name, checked=YesNoFormat(ListFind(ValueList(selectedToppings.id), toppings.id))#
	</cfoutput>
</fieldset>