Source for file field.php
Documentation is available at field.php
* database primitive object for an individual field within a row
* @author Stuart Prescott
* @copyright Copyright Stuart Prescott
* @license http://opensource.org/licenses/gpl-license.php GNU Public License
* @subpackage FormsLibrary
/** Load ancillary functions */
require_once 'inc/typeinfo.php';
/** type checking and data manipulation */
require_once 'validtester.php';
/** status codes for success/failure of database actions */
require_once 'inc/statuscodes.php';
* Field object that corresponds to one field in a SQL table row.
* A number of fields would normally be held together in a DBRow,
* with the DBRow object controlling the updating to the SQL database.
* Typical usage is through inheritance, see example for DBRow.
* $f = new TextField("name", "Name");
* @subpackage FormsLibrary
/** @var string name of this field */
/** @var string label for the field in the display */
/** @var string description for the field in the mouse-over */
/** @var boolean field is required */
/** @var string value of this field */
/** @var string previous value of this field*/
/** @var string default value of the field */
/** @var string duplicate the value of this field (when hidden) in a hidden field with this name */
/** @var tristate this field is editable */
/** @var string the value of this field has changed */
/** @var string the field is a hidden widget */
/** @var string the data contained by the field is valid */
/** @var string if the ID changes, then notify descendents */
/** @var tristate don't to validation on this field */
/** @var boolean permit NULL values in this field */
/** @var array display attributes */
/** @var string CSS class to be used for marking fields with errors */
/** @var string prepended to the name of the field in the html id and hence in the data array */
/** @var string function to call to check that the data is valid */
/** @var string function to call to clean the data string before testing if valid */
/** @var boolean don't generate an SQL name=value representation for this field */
/** @var boolean this field requires two-stage sync */
/** @var string status code of the descendents of this field (out-of-band data reporting) */
/** @var string error message from this field or its descendents */
/** @var integer debug log level */
* Create a new generic field object, designed to be superclasses
* @param string $name the name of the field (db name, and html field name
* @param string $longname long name to be used in the label of the field in display
* @param string $description used in the html title or longdesc for the field
function Field($name, $longname=
'', $description=
'') {
* update the value of the object with the user-supplied data in $data
* $data is most probably from POST data etc.
* The validity of the data is *not* checked at this stage, the object
* only takes the user-supplied value.
* $data is an array with the data relevant to this field being
* in the key $this->namebase.$this->name.
* $this->namebase = 'person-';
* $this->name = 'phonenumber';
* $data['person-phonenumber'] // used for the value
* @param array $data is name => value pairs as above
* @return boolean did the value of this object change?
// we ignore new values if the field is not editable
//ensure that the value is copied in from the default value if
* Check the validity of the current data value.
* This also checks the validity of the data even if the data is not newly-entered.
* Returns true if the specified validity tests are passed:
* - is the field required to be filled in && is it filled in?
* - is there a validity test && is the data valid?
* @return boolean is the data value valid
#$this->isValid = (isset($this->value) && $this->value != "");
$this->log($this->name .
' Required: '.
($this->isValid ?
' VALID' :
' INVALID'));
* set the value of this field
* <b>without</b> validation or checking to see whether the field has changed.
* @param string the new value for this field
//echo "Updating field $this->name. New value=$value\n";
* create an SQL-injection-cleansed string for db statements
* Generates a string that represents this field that can be used in an SQL
* UPDATE or INSERT statement. i.e. "name='Stuart'".
* @param string optional SQL name to use to change the default
* @param boolean optional force the generation of the command
* @return string in SQL assignable form
* Set display attributes for the field.
* the attribute fielde are parsed differently for each different field subclass
* @param array $attrs attribute_name => value
* Quick and dirty display of the field status
* @return string simple text representation of the class's value and attributes
$t .=
($this->editable ?
"(editable)" :
"(read-only)");
$t .=
($this->isValid ?
"" :
"(invalid)");
* Generic display function
* html representation of this field as a "hidden" form widget
return "<input type='hidden' name='$this->namebase$this->name' "
* render this form widget in an html table
* @param integer $cols number of columns to be included in table (padding cols will be added)
* return the current value as text and the widget as a hidden form element
* @return string current value
* return an html representation of the widget
* @return string html widget
* Obtain the value of the field, taking account of default values
* @return mixed field value
//echo "FIELD $this->name: ".$this->value.":".$this->defaultValue."<br />";
* set whether this field is editable or not
* @param boolean $editable new editable state
* set the namebase for the data storage in the html form
* @param boolean $editable new editable state
* Generic logging function
* @param string $logstring data to log
* @param integer $priority log level for this message
function log($logstring, $priority=
10) {
if ($priority <=
$this->DEBUG) {
echo
$logstring.
"<br />\n";
* PHP5 clone statement will perform only a shallow copy of the object. Any subobjects must also be cloned
// Force a copy of contents of $this->list
Documentation generated on Tue, 06 Mar 2007 10:01:32 +0000 by phpDocumentor 1.3.0