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