Back
textField()
Builds and returns an HTML text field form control that is bound to a model object and one of its properties. By default, it will populate the value of the field from the property on the object. You can pass additional attributes such as class, id, or rel to customize the rendered tag. When working with nested associations or hasMany relationships, you can use the association and position arguments to bind the field to related properties. Wheels also supports automatically generating and placing labels, wrapping controls with custom HTML, and marking fields with errors when validation fails. The type argument lets you adjust the input type for use with HTML5 attributes like email, tel, or url.
1. Basic text field with label
#textField(label="First Name", objectName="user", property="firstName")#
2. Using a custom input type
#textField(
label="Email Address",
objectName="user",
property="email",
type="email"
)#
3. Adding CSS classes and attributes
#textField(
label="Phone",
objectName="contact",
property="phoneNumber",
class="form-control",
placeholder="Enter phone number"
)#
4. Nested form with hasMany association
<fieldset>
<legend>Phone Numbers</legend>
<cfloop from="1" to="#ArrayLen(contact.phoneNumbers)#" index="i">
#textField(
label="Phone ##i#",
objectName="contact",
association="phoneNumbers",
position=i,
property="phoneNumber"
)#
</cfloop>
</fieldset>
5. Prepending and appending HTML wrappers
#textField(
label="Website",
objectName="company",
property="website",
prepend="<div class='field-wrapper'>",
append="</div>"
)#
6. Handling validation errors
#textField(
label="Username",
objectName="user",
property="username",
errorElement="div",
errorClass="input-error"
)#
Copied!