Webylon 3.1 API Docs
  • Package
  • Class
  • Tree
  • Deprecated
  • Download
Version: current
  • 3.2
  • 3.1

Packages

  • auth
  • Booking
  • cart
    • shipping
    • steppedcheckout
  • Catalog
  • cms
    • assets
    • batchaction
    • batchactions
    • bulkloading
    • comments
    • content
    • core
    • export
    • newsletter
    • publishers
    • reports
    • security
    • tasks
  • Dashboard
  • DataObjectManager
  • event
  • faq
  • forms
    • actions
    • core
    • fields-basic
    • fields-dataless
    • fields-datetime
    • fields-files
    • fields-formatted
    • fields-formattedinput
    • fields-relational
    • fields-structural
    • transformations
    • validators
  • googlesitemaps
  • guestbook
  • installer
  • newsletter
  • None
  • photo
    • gallery
  • PHP
  • polls
  • recaptcha
  • sapphire
    • api
    • bulkloading
    • control
    • core
    • cron
    • dev
    • email
    • fields-formattedinput
    • filesystem
    • formatters
    • forms
    • i18n
    • integration
    • misc
    • model
    • parsers
    • search
    • security
    • tasks
    • testing
    • tools
    • validation
    • view
    • widgets
  • seo
    • open
      • graph
  • sfDateTimePlugin
  • spamprotection
  • stealth
    • captha
  • subsites
  • userform
    • pagetypes
  • userforms
  • webylon
  • widgets

Classes

  • CheckboxField
  • CheckboxField_Disabled
  • CheckboxField_Readonly
  • CheckboxSetField
  • DropdownField
  • GroupedDropdownField
  • ListboxField
  • LookupField
  • NullableField
  • OptionsetField
  • ReadonlyField
  • RoomServiceDropdownField
  • SimpleHTMLEditorField
  • SimpleTinyMCEField
  • SimpleWysiwygField
  • StateDropdownField
  • StateProvinceDropdownField
  • TextareaField
  • TextField
  1 <?php
  2 /**
  3  * Single checkbox field.
  4  * @package forms
  5  * @subpackage fields-basic
  6  */
  7 class CheckboxField extends FormField {
  8      
  9     protected $disabled;
 10 
 11     function setValue($value) {
 12         $this->value = ($value) ? 1 : 0;
 13     }
 14 
 15     function dataValue() {
 16         return ($this->value) ? 1 : 0;
 17     }
 18     
 19     function Value() {
 20         return ($this->value) ? 1 : 0;
 21     }
 22     
 23     function Field() {
 24         $attributes = array(
 25             'type' => 'checkbox',
 26             'class' => ($this->extraClass() ? $this->extraClass() : ''),
 27             'id' => $this->id(),
 28             'name' => $this->Name(),
 29             'value' => 1,
 30             'checked' => $this->value ? 'checked' : '',
 31             'tabindex' => $this->getTabIndex()
 32         );
 33         
 34         if($this->disabled) $attributes['disabled'] = 'disabled';
 35         
 36         return $this->createTag('input', $attributes);
 37     }
 38 
 39     /**
 40      * Checkboxes use the RightLabelledFieldHolder template, to put the field on the left
 41      * and the label on the right.  See {@link FormField::FieldHolder} for more information about
 42      * how FieldHolder works. 
 43      */
 44     function FieldHolder() {
 45         if($this->labelLeft) {
 46             return parent::FieldHolder();
 47         } else {
 48             extract($this->getXMLValues(array( 'Name', 'Field', 'Title', 'Message', 'MessageType' )),
 49                 EXTR_SKIP);
 50             $messageBlock = isset($Message) ? "<span class=\"message $MessageType\">$Message</span>" : '';
 51             $Type = $this->XML_val('Type');
 52             $extraClass = $this->XML_val('extraClass'); 
 53             $RightBlock = ($this->RightTitle()) ? '<span class="right">'.$this->XML_val('RightTitle').'</span>' : '';
 54             return <<<HTML
 55 <p id="$Name" class="field $Type $extraClass">
 56     <span class="middleColumn middlecolumn">$Field
 57     <label class="right" for="{$this->id()}">$Title</label></span>
 58     $RightBlock
 59     $messageBlock
 60 </p>
 61 HTML;
 62             
 63         }
 64     }
 65 
 66     function useLabelLeft( $labelLeft = true ) {
 67         $this->labelLeft = $labelLeft;
 68     }
 69 
 70     /**
 71      * Returns a restricted field holder used within things like FieldGroups
 72      */
 73     function SmallFieldHolder() {
 74         $result = $this->Field();
 75         if($t = $this->Title()) {
 76             $result .= "<label for=\"" . $this->id() ."\">$t</label> ";
 77         }
 78         return $result;
 79     }
 80 
 81     /**
 82      * Returns a readonly version of this field
 83      */
 84      
 85     function performReadonlyTransformation() {
 86         $field = new CheckboxField_Readonly($this->name, $this->title, $this->value ? _t('CheckboxField.YES', 'Yes') : _t('CheckboxField.NO', 'No'));
 87         $field->setForm($this->form);
 88         return $field;  
 89     }
 90     
 91     function performDisabledTransformation() {
 92         $clone = clone $this;
 93         $clone->setDisabled(true);
 94         return $clone;
 95     }
 96 }
 97 
 98 /**
 99  * Readonly version of a checkbox field - "Yes" or "No".
100  * @package forms
101  * @subpackage fields-basic
102  */
103 class CheckboxField_Readonly extends ReadonlyField {
104     function performReadonlyTransformation() {
105         return clone $this;
106     }
107     
108     function setValue($val) {
109         $this->value = (int)($val) ? _t('CheckboxField.YES', 'Yes') : _t('CheckboxField.NO', 'No');
110     }
111 }
112 
113 /**
114  * Single checkbox field, disabled
115  * @package forms
116  * @subpackage fields-basic
117  */
118 class CheckboxField_Disabled extends CheckboxField {
119     
120     protected $disabled = true;
121     
122     /**
123      * Returns a single checkbox field - used by templates.
124      */
125     function Field() {
126         $attributes = array(
127             'type' => 'checkbox',
128             'class' => 'text' . ($this->extraClass() ? $this->extraClass() : ''),
129             'id' => $this->id(),
130             'name' => $this->Name(),
131             'tabindex' => $this->getTabIndex(),
132             'checked' => ($this->value) ? 'checked' : false,
133             'disabled' => 'disabled' 
134         );
135         
136         return $this->createTag('input', $attributes);
137     }
138 }
139 ?>
[Raise a SilverStripe Framework issue/bug](https://github.com/silverstripe/silverstripe-framework/issues/new)
- [Raise a SilverStripe CMS issue/bug](https://github.com/silverstripe/silverstripe-cms/issues/new)
- Please use the Silverstripe Forums to ask development related questions. -
Webylon 3.1 API Docs API documentation generated by ApiGen 2.8.0