Back
radioButtonTag()
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.
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"
)#
Copied!