View Helpers
radioButtonTag()
Signature
Section titled “Signature”radioButtonTag() — returns string
Available in: controller
Category: Form Tag Functions
Description
Section titled “Description”Generates a standard HTML <input type=“radio”> element based on the supplied name and value. Unlike radioButton(), this function works directly with form tags rather than binding to a model object. It is useful for simple forms or when you need fine-grained control over the HTML attributes. You can customize the radio button with labels, label placement, HTML wrapping, and encoding to prevent XSS attacks. The generated radio button will be marked as checked if the checked argument is true.
Parameters
Section titled “Parameters”| Name | Type | Required | Default | Description |
|---|---|---|---|---|
name | string | yes | — | Name to populate in tag’s name attribute. |
value | string | yes | — | Value to populate in tag’s value attribute. |
checked | boolean | no | false | Whether or not to check the radio button by default. |
label | string | no | — | The label text to use in the form control. |
labelPlacement | string | no | around | Whether to place the label before, after, or wrapped around the form control. Label text placement can be controlled using aroundLeft or aroundRight. |
prepend | string | no | — | String to prepend to the form control. Useful to wrap the form control with HTML tags. |
append | string | no | — | String to append to the form control. Useful to wrap the form control with HTML tags. |
prependToLabel | string | no | — | String to prepend to the form control’s label. Useful to wrap the form control with HTML tags. |
appendToLabel | string | no | — | String to append to the form control’s label. Useful to wrap the form control with HTML tags. |
encode | any | no | true | Use 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. |
Examples
Section titled “Examples”1. Basic radio buttons for gender
<cfoutput>
<fieldset>
<legend>Gender</legend>
#radioButtonTag(name="gender", value="m", label="Male", checked=true)#<br>
#radioButtonTag(name="gender", value="f", label="Female")#
</fieldset>
</cfoutput>
2. Label before radio button
#radioButtonTag(name="subscription", value="premium", label="Premium Plan", labelPlacement="before")#
3. Custom HTML wrappers
#radioButtonTag(
name="newsletter",
value="yes",
label="Subscribe",
prepend="<div class='radio-wrapper'>",
append="</div>",
labelPlacement="aroundRight"
)#