Comments: on this page. Click to read or post your own.

Class FormField

Description

Represents a field in a form.

A FieldSet contains a number of FormField objects which make up the whole of a form. In addition to single fields, FormField objects can be "composite", for example, the TabSet field. Composite fields let us define complex forms without having to resort to custom HTML.

Located in /sapphire/forms/FormField.php (line 10)

Object
   |
   --ViewableData
      |
      --RequestHandlingData
         |
         --FormField
Direct descendents
Class Description
RequestHandlingTest_FormField Form field for the test
ReadonlyField Read-only field, with <label> and <span>
TextareaField Multi-line text area.
FileField Represents a file type which can be added to a form.
HiddenField Hidden field.
ConfirmedPasswordField Shows two password-fields, and checks for matching passwords.
CompositeField Base class for all fields that contain other fields.
TreeSelectorField
PhoneNumberField Field for displaying phone numbers. It separates the number, the area code and optionally the country code and extension.
BankAccountField Field for displaying bank account numbers. It separates the bank, branch, account-number and account-suffix.
InlineFormAction Render a button that will act as If you want to add custom behaviour, please set {inlcudeDefaultJS} to false and work with behaviour.js.
InlineFormAction_ReadOnly Readonly version of InlineFormAction.
DropdownField Dropdown field, created from a <select> tag.
TableListField Form field that embeds a list into a form, such as a member list or a file list.
DatalessField Abstract class for all fields without data.
FormAction Single action button.
TreeDropdownField Dropdown-like field that gives you a tree of items, using ajax.
SimpleImageField_Disabled Disabled version of SimpleImageField.
RelatedDataEditor RelatedDataEditor puts a "sub-form" into a form that lets you edit a record on the other side of a one-to-many relationship. For example, you could be editing a workshop, and you want to provide fields to edit the client contact for that workshop.
CheckboxField Single checkbox field.
ReportField Displays complex reports based on the list of tables and fields provided to the object.
PasswordField Password input field.
TextField Text input field.
WidgetAreaEditor Special field type for selecting and configuring widgets on a page.
NewsletterList Represents a field in a form.
BouncedList Represents a field in a form.
RecipientImportField Displays a file upload field.
UnsubscribedList Displays a list of all members that have unsubscribed from the list
ThumbnailStripField Provides a strip of thumbnails showing all of the images in the system.
MemberList Represents a field in a form.
Variable Summary
$description $description
$disabled $disabled
mixed $dontEscape
mixed $extraClass
$extraClasses $extraClasses
mixed $form
$leftTitle $leftTitle
mixed $message
mixed $messageType
mixed $name
$readonly $readonly
$rightTitle $rightTitle
int $tabIndex
mixed $title
mixed $value
Method Summary
FormField __construct (name $name, [title $title = null], [value $value = null], [form $form = null], [maxLength $rightTitle = null])
void addExtraClass ($class $class)
void attrName ()
void attrTitle ()
void attrValue ()
void createTag ( $tag,  $attributes, [ $content = null])
void dataValue ()
void debug ()
void describe ( $description)
String extraClass ()
void Field ()
void FieldHolder ()
void forTemplate ()
int getTabIndex ()
string getTabIndexHTML ([int $increment = 0])
void hasClass ( $class)
void hasData ()
void id ()
void isComposite ()
boolean isDisabled ()
boolean isReadonly ()
void jsValidation ()
void LeftTitle ()
void Link ()
void Message ()
void MessageType ()
void Name ()
string name_to_label (string $fieldName)
void removeExtraClass ($class $class)
void Required ()
void RightTitle ()
void rootFieldSet ()
void saveInto ( $record)
void setContainerFieldSet (FieldSet $containerFieldSet)
void setDisabled ($bool $bool)
void setError ( $message,  $messageType)
void setForm ( $form)
void setLeftTitle ( $val)
void setName ( $name)
void setReadonly ($bool $bool)
void setRightTitle ( $val)
void setTabIndex (int $index)
void setTitle ( $val)
void setValue ( $value)
void Title ()
void transform (FormTransformation $trans)
void Type ()
void validate ()
void Value ()
Variables
FieldSet $containerFieldSet (line 49)

Stores a reference to the FieldSet that contains this object.

  • access: protected
$description $description (line 18)
  • var: string Adds a "title"-attribute to the markup.
  • todo: Implement in all subclasses
  • access: protected
$disabled $disabled = false (line 59)
  • var: boolean
  • access: protected

Redefined in descendants as:
mixed $dontEscape (line 25)
  • access: public
mixed $extraClass (line 12)
  • access: protected
$extraClasses $extraClasses (line 23)
  • var: array Extra CSS-classes for the formfield-container
  • access: protected
mixed $form (line 11)
  • access: protected
$leftTitle $leftTitle (line 36)
  • var: string Used in SmallFieldHolder() to force a left-aligned label with correct spacing. Please use $title for FormFields rendered with DefaultFieldHolder.
  • access: protected
mixed $message (line 12)
  • access: protected
mixed $messageType (line 12)
  • access: protected
mixed $name (line 12)
  • access: protected
$readonly $readonly = false (line 54)
  • var: boolean
  • access: protected

Redefined in descendants as:
$rightTitle $rightTitle (line 30)
  • var: string Used in SmallFieldHolder() to force a right-aligned label.
  • access: protected
int $tabIndex (line 43)

Set the "tabindex" HTML attribute on the field.

  • access: protected
mixed $title (line 12)
  • access: protected
mixed $value (line 12)
  • access: protected

Inherited Variables

Inherited from RequestHandlingData

RequestHandlingData::$allowed_actions
RequestHandlingData::$request
RequestHandlingData::$url_handlers

Inherited from ViewableData

ViewableData::$casting
ViewableData::$castingHelperPair_cache
ViewableData::$customisedObj
ViewableData::$failover
ViewableData::$iteratorPos
ViewableData::$iteratorTotalItems
ViewableData::$namedAs
ViewableData::$parent
ViewableData::$_natural_cache
ViewableData::$_object_cache
ViewableData::$_xml_cache

Inherited from Object

Object::$builtInMethods
Object::$class
Object::$classConstructed
Object::$extensions
Object::$extension_instances
Object::$extraMethods
Object::$extraStatics
Object::$statics
Object::$static_cached
Methods
Constructor __construct (line 69)

Create a new field.

FormField __construct (name $name, [title $title = null], [value $value = null], [form $form = null], [maxLength $rightTitle = null])
  • name $name: The internal field name, passed to forms.
  • title $title: The field label.
  • value $value: The value of the field.
  • form $form: Reference to the container form
  • maxLength $rightTitle: The Maximum length of the attribute

Redefinition of:
Object::__construct()

Redefined in descendants as:
addExtraClass (line 224)

Add a CSS-class to the formfield-container.

void addExtraClass ($class $class)
  • $class $class: String
attrName (line 104)
void attrName ()
attrTitle (line 240)

Returns a version of a title suitable for insertion into an HTML attribute

void attrTitle ()
attrValue (line 246)

Returns a version of a title suitable for insertion into an HTML attribute

void attrValue ()

Redefined in descendants as:
  • TimeField::attrValue() : Added to the value of the input, put the date into the format specified in the constructer.
createTag (line 447)

Construct and return HTML tag

void createTag ( $tag,  $attributes, [ $content = null])
  • $tag
  • $attributes
  • $content
dataValue (line 142)

Returns the field value suitable for insertion into the data object

void dataValue ()

Redefined in descendants as:
debug (line 484)
void debug ()

Redefined in descendants as:
describe (line 479)

Describe this field, provide help text for it.

The function returns this so it can be used like this: $action = FormAction::create('submit', 'Submit')->describe("Send your changes to be approved")

void describe ( $description)
  • $description
extraClass (line 209)

Compiles all CSS-classes. Optionally includes a "nolabel"-class if no title was set on the formfield.

  • return: CSS-classnames
String extraClass ()

Redefined in descendants as:
Field (line 298)

Returns the form field - used by templates.

Although FieldHolder is generally what is inserted into templates, all of the field holder templates make use of $Field. It's expected that FieldHolder will give you the "complete" representation of the field on the form, whereas Field will give you the core editing widget, such as an input tag.

Our base FormField class just returns a span containing the value. This should be overridden!

void Field ()

Redefined in descendants as:
FieldHolder (line 316)

Returns a "Field Holder" for this field - used by templates.

Forms are constructed from by concatenating a number of these field holders. The default field holder is a label and form field inside a paragraph tag.

Composite fields can override FieldHolder to create whatever visual effects you like. It's a good idea to put the actual HTML for field holders into templates. The default field holder is the DefaultFieldHolder template. This lets you override the HTML for specific sites, if it's necessary.

  • todo: Add "validationError" if needed.
void FieldHolder ()

Redefined in descendants as:
forTemplate (line 492)

This function is used by the template processor. If you refer to a field as a $ variable, it will return the $Field value.

void forTemplate ()
getForm (line 276)

Get the currently used form.

Form getForm ()
getTabIndex (line 188)

Get tabindex (if previously set)

  • access: public
int getTabIndex ()
getTabIndexHTML (line 198)

Get tabindex HTML string

  • access: protected
string getTabIndexHTML ([int $increment = 0])
  • int $increment: Increase current tabindex by this value
hasClass (line 431)
void hasClass ( $class)
  • $class
hasData (line 368)

Returns true if this field has its own data.

Some fields, such as titles and composite fields, don't actually have any data. It doesn't make sense for data-focused methods to look at them. By overloading hasData() to return false, you can prevent any data-focused methods from looking at it.

void hasData ()

Redefined in descendants as:
id (line 91)

Returns the HTML ID of the field - used in the template by label tags.

The ID is generated as FormName_FieldName. All Field functions should ensure that this ID is included in the field.

void id ()

Redefined in descendants as:
isComposite (line 358)

Returns true if this field is a composite field.

To create composite field types, you should subclass CompositeField.

void isComposite ()

Redefined in descendants as:
isDisabled (line 389)
boolean isDisabled ()
isReadonly (line 373)
boolean isReadonly ()
jsValidation (line 464)

javascript handler Functions for each field type by default formfield doesnt have a validation function

  • todo: shouldn't this be an abstract method?
void jsValidation ()

Redefined in descendants as:
LeftTitle (line 165)
void LeftTitle ()
Link (line 82)

Return a Link to this field

void Link ()
Message (line 111)

Returns the field message, used by form validation

void Message ()

Redefined in descendants as:
MessageType (line 118)

Returns the field message type, used by form validation

void MessageType ()

Redefined in descendants as:
Name (line 100)

Returns the field name - used by templates.

void Name ()

Redefined in descendants as:
name_to_label (line 513)

Takes a fieldname and converts camelcase to spaced words. Also resolves combined fieldnames with dot syntax to spaced words.

string name_to_label (string $fieldName)
  • string $fieldName
performDisabledTransformation (line 415)

Return a disabled version of this field

void performDisabledTransformation ()

Redefined in descendants as:
performReadonlyTransformation (line 405)

Returns a readonly version of this field

void performReadonlyTransformation ()

Redefined in descendants as:
removeExtraClass (line 233)

Remove a CSS-class from the formfield-container.

void removeExtraClass ($class $class)
  • $class $class: String
Required (line 496)
void Required ()
RightTitle (line 157)
void RightTitle ()
rootFieldSet (line 534)
void rootFieldSet ()

Redefined in descendants as:
saveInto (line 133)

Method to save this form field into the given data object.

By default, makes use of $this->dataValue()

void saveInto ( $record)

Redefined in descendants as:
setContainerFieldSet (line 530)

Set the fieldset that contains this field.

void setContainerFieldSet (FieldSet $containerFieldSet)
setDisabled (line 398)

Sets disabed-flag on form-field. Please use performDisabledTransformation() to actually transform this instance.

void setDisabled ($bool $bool)
  • $bool $bool: boolean Setting "false" has no effect on the field-state.

Redefined in descendants as:
setError (line 284)

Sets the error message to be displayed on the form field

Set by php validation of the form

void setError ( $message,  $messageType)
  • $message
  • $messageType
setForm (line 267)

Set the container form.

This is called whenever you create a new form and put fields inside it, so that you don't have to worry about linking the two.

void setForm ( $form)
  • $form

Redefined in descendants as:
setLeftTitle (line 169)
void setLeftTitle ( $val)
  • $val
setName (line 259)

Set the field name

void setName ( $name)
  • $name
setReadonly (line 382)

Sets readonly-flag on form-field. Please use performReadonlyTransformation() to actually transform this instance.

void setReadonly ($bool $bool)
  • $bool $bool: boolean Setting "false" has no effect on the field-state.
setRightTitle (line 161)
void setRightTitle ( $val)
  • $val

Redefined in descendants as:
setTabIndex (line 179)

Set tabindex HTML attribute (defaults to none).

  • access: public
void setTabIndex (int $index)
  • int $index
setTitle (line 153)
void setTitle ( $val)
  • $val
setValue (line 254)

Set the field value.

Returns $this.

void setValue ( $value)
  • $value

Redefined in descendants as:
SmallFieldHolder (line 337)

Returns a restricted field holder used within things like FieldGroups.

void SmallFieldHolder ()

Redefined in descendants as:
Title (line 149)

Returns the field label - used by templates.

void Title ()

Redefined in descendants as:
transform (line 427)
void transform (FormTransformation $trans)

Redefined in descendants as:
Type (line 442)

Returns the field type - used by templates.

The field type is the class name with the word Field dropped off the end, all lowercase. It's handy for assigning HTML classes.

void Type ()

Redefined in descendants as:
validate (line 472)

Validation Functions for each field type by default formfield doesnt have a validation function

  • todo: shouldn't this be an abstract method?