1: <?php
2: 3: 4: 5: 6: 7: 8: 9: 10: 11:
12:
13: 14: 15: 16: 17: 18: 19: 20:
21: class Form_Element_Text extends Form_Input
22: {
23: 24: 25: 26: 27: 28:
29: protected $minLength;
30:
31: 32: 33: 34: 35: 36: 37:
38: public function __construct($nom,$form)
39: {
40: parent::__construct($nom,$form);
41: if(!isset($this->attrs['type']))
42: $this->setAttributes('type','text');
43: $this->minLength = 0;
44: }
45:
46: 47: 48: 49: 50: 51: 52:
53: public function minLength($taille)
54: {
55: if(ctype_digit((string)$taille) && $taille>=0)
56: $this->minLength = $taille;
57: return $this;
58: }
59:
60: 61: 62: 63: 64: 65:
66: public function isValid($value)
67: {
68: if(parent::isValid($value))
69: {
70: if(!$this->required && empty($value))
71: return true;
72: if(!$this->minLength == 0)
73: $carac = $this->minLength -1;
74: else
75: return true;
76:
77: if(isset($value[$carac]))
78: return true;
79: else
80: $this->errorMsg = Form_Error::TOOSHORT.$this->minLength;
81: }
82: return false;
83: }
84: 85: 86: 87: 88: 89:
90: public function __toString()
91: {
92:
93: $css = $this->cssClass();
94: $label = '';
95: if(!empty($this->label))
96: {
97: $label = "\t".'<label for="'.$this->attrs['id'].'" class="'.$this->cssLabel.'">'.$this->label.'</label>'."\n";
98: if($this->labelNewLine)
99: $label.="\t".'<br />'."\n";
100: }
101: $attributs = $this->attrsToString();
102:
103: $value = $this->form->getPostedvalue($this->attrs['name']);
104: if(empty($value))
105: $value = $this->value;
106:
107: $field = "\t".'<input '.$css.' value="'.htmlspecialchars($value).'" '.$attributs.' />'."\n";
108:
109: $error='';
110: if(!is_null($this->errorMsg))
111: {
112: $error='<span class="'.$this->errorClass.'">'.$this->errorMsg.'</span><br />';
113: }
114: if(!empty($this->info))
115: $field.="\t".'<img src="'.$this->imgInfo.'" id="'.$this->attrs['name'].'_tooltip" class="form_tooltip" title="'.$this->info.'" alt="" style="cursor:help;" />';
116: if($this->fieldNewLine)
117: $field.="\t".'<br />'."\n";
118: return $label.$field.$error;
119: }
120: }
121: ?>