Orion PHP  0.11.12
The PHP5.3 framework
field.php
Go to the documentation of this file.
00001 <?php
00002 namespace Orion\Core\Form;
00003 
00004 /**
00005  * Base form field class.
00006  *
00007  * Contrary to OrionModelFields, these fields are used only for form creation. Never for DB model handling.
00008  * Extend this abstract class when creating a new form field class. (Customfield extends Field).
00009  * <b>Be sure to specify at least $bind and $type attributes</b>
00010  */
00011 abstract class Field
00012 {
00013     /**
00014      * Override this function to define a specific (x)HTML form field to use during model-to-form translation.
00015      * @param boolean $XHTML
00016      * @return string
00017      */
00018     public abstract function toHtml($XHTML=true);
00019 
00020     /**
00021      * Sets field visibility in Form creation
00022      * @var boolean
00023      */
00024     protected $visible=true;
00025     /**
00026      * Set this to true if this field need the form type to be multipart (like a file uploader for example).
00027      * @var boolean
00028      */
00029     protected $multipart=false;
00030     /**
00031      * The field's value
00032      * @var mixed
00033      */
00034     protected $value;
00035     /**
00036      * Standard field type identifier
00037      * @var string
00038      */
00039     protected $type;
00040     /**
00041      * Field identifier (used as field ID, and such)
00042      * @var string
00043      */
00044     protected $bind;
00045     /**
00046      * Field label, used for display and form labelling purposes
00047      * @var string
00048      */
00049     protected $label='OrionField';
00050     /**
00051      * Set this to true if it's a required field
00052      * @var boolean
00053      */
00054     protected $required=false;
00055 
00056     /**
00057      * Retreive field's label
00058      * @return string
00059      */
00060         public function getLabel()
00061         {
00062                 return $this->label;
00063         }
00064 
00065     /**
00066      * Retreive field's type
00067      * @return string
00068      */
00069         public function getType()
00070         {
00071 
00072                 return $this->type;
00073         }
00074 
00075     /**
00076      * Retreive field's binding (field ID)
00077      * @return string
00078      */
00079         public function getBinding()
00080         {
00081                 return $this->bind;
00082         }
00083 
00084     /**
00085      * Same as getBinding(), just a more common name. Retreive field's binding (field ID)
00086      * @return string
00087      */
00088     public function getName()
00089     {
00090         return $this->bind;
00091     }
00092 
00093     /**
00094      * Retreive field's value
00095      * @return string
00096      */
00097     public function getValue()
00098     {
00099         return $this->value;
00100     }
00101 
00102     /**
00103      * Set field's value
00104      */
00105     public function setValue($val)
00106     {
00107         $this->value = $val;
00108     }
00109 
00110     /**
00111      * Set field's form visibility
00112      */
00113     public function setVisibility($bool)
00114     {
00115         $this->visible = $bool;
00116     }
00117 
00118     /**
00119      * Check if the field's value is empty (override for specific cases)
00120      * @return boolean
00121      */
00122     public function isEmptyValue($value)
00123     {
00124         return ($value == null || $value == '' || $value == "''");
00125     }
00126 
00127     /**
00128      * Check if the field needs a multipart form type
00129      * @return boolean
00130      */
00131     public function isMultipart()
00132     {
00133         return $this->multipart;
00134     }
00135 
00136     /**
00137      * Check if the field is required
00138      * @return boolean
00139      */
00140     public function isRequired()
00141     {
00142         return $this->required;
00143         }
00144 
00145     /**
00146      * Check if the field is visible in form creation
00147      * @return boolean
00148      */
00149     public function isVisible()
00150     {
00151         return $this->visible;
00152     }
00153 
00154     public function  __toString()
00155     {
00156         return '[Field] '.$this->label.' with id: '.$this->bind;
00157     }
00158 }
00159 
00160 ?>