Go to the documentation of this file.00001 <?php
00010 abstract class form_abstract extends object {
00011
00017 protected $valid;
00018
00024 protected $customErrors = array();
00025
00029 protected function afterInit() {
00030 if (!$this->label && !is_bool($this->label))
00031 $this->label = ucfirst($this->name);
00032 if (!is_object($this->cfg->value))
00033 $this->cfg->value = utils::htmlOut($this->cfg->value);
00034 $this->id = $this->makeId($this->name);
00035 $val = &$this->cfg->getRef('value');
00036 $this->valid = factory::get($this->cfg->validType, array(
00037 'value'=>&$val,
00038 'label'=>$this->label,
00039 'validEltArray'=>$this->cfg->getInArray('valid', 'validEltArray'),
00040 ));
00041 $this->cfg->delInArray('valid', 'validEltArray');
00042 $this->initValid();
00043 }
00044
00045 public function renew() {
00046 $this->id = $this->makeId($this->name);
00047 }
00048
00055 protected function makeId($name) {
00056 return str_replace(
00057 array('[]', '[', ']'),
00058 array('_', '_', ''),
00059 $name);
00060 }
00066 public function getName() {
00067 return $this->cfg->name;
00068 }
00069
00075 public function getValue() {
00076 return utils::htmlDeOut($this->cfg->value);
00077 }
00078
00084 public function &getRawValue() {
00085 return $this->cfg->getRef('value');
00086 }
00087
00094 public function setValue($value, $refill=false) {
00095 if ($this->cfg->disabled)
00096 return;
00097 $this->cfg->set('value', utils::htmlOut($value));
00098 }
00099
00105 public function getDescription() {
00106 $ret = $this->cfg->description;
00107 if ($this->cfg->outDescription)
00108 $ret = utils::htmlOut($ret);
00109 return $ret;
00110 }
00111
00115 protected function initValid() {
00116 $valid = $this->cfg->valid;
00117 if (is_array($valid)) {
00118 foreach($valid as $type=>$prm)
00119 if (is_int($type))
00120 $this->addRule($prm);
00121 else if ($prm)
00122 $this->addRule($type, $prm);
00123 } else
00124 $this->addRule($valid);
00125 }
00126
00132 public function getValid() {
00133 return $this->valid;
00134 }
00135
00141 public function isValid() {
00142 return $this->valid->isValid() && empty($this->customErrors);
00143 }
00144
00151 public function getValidRule($name) {
00152 if (!$this->valid)
00153 return null;
00154 $tmp = $this->valid->getRules();
00155 return array_key_exists($name, $tmp) ? $tmp[$name] : null;
00156 }
00157
00163 public function setDisabled($disabled) {
00164 $this->cfg->disabled = $disabled;
00165 if ($disabled)
00166 $this->cfg->setInArray('html', 'disabled', 'disabled');
00167 else
00168 $this->cfg->delInArray('html', 'disabled');
00169 }
00170
00176 public function getErrors() {
00177 return array_merge_recursive($this->valid->getErrors(), $this->customErrors);
00178 }
00179
00185 public function addCustomError($error) {
00186 $this->customErrors[] = $error;
00187 }
00188
00195 public function addRule($type, $prm=null) {
00196 $this->valid->addRule($type, $prm);
00197 }
00198
00204 public function delRule($type) {
00205 $this->valid->delRule($type);
00206 }
00207
00213 public function isHidden() {
00214 return false;
00215 }
00216
00222 public function getType() {
00223 return substr(get_class($this), strlen('form_'));
00224 }
00225
00232 public function to($type) {
00233 return $this->{'to'.ucfirst($type)}();
00234 }
00235
00239 abstract public function toHtml();
00240
00244 public function toXul() {
00245 return '';
00246 }
00247
00253 public function __toString() {
00254 return $this->to(request::get('out'));
00255 }
00256
00263 public function __get($name) {
00264 return $this->cfg->get($name);
00265 }
00266
00273 public function __set($name, $val) {
00274 return $this->cfg->set($name, $val);
00275 }
00276
00277 }