_name = $name; $this->_value = $value; } public function getName() { return $this->_name; } abstract public function output(); } //處理文字輸入欄位的類別,繼承FormElement,並覆寫 output方法,輸出input標籤動態元件 class FormElement_input extends FormElement { private $_type; public function set_type($type){ $this->_type=$type; } public function output() { return ''; } } //圖片類別也是繼承FormElement類別,並覆寫output方法,輸出img標籤動態元件 class FormElement_Image extends FormElement { public function output() { return ''; } } //送出按鈕類別也是繼承FormElement類別,並覆寫output方法,輸出button標籤動態元件 class FormElement_Submit extends FormElement { public function output() { return '' . htmlspecialchars($this->_value) .''; } } //大量文字框也是繼承FormElement類別,並覆寫output方法,輸出textarea標籤動態元件 class FormElement_textarea extends FormElement { private $_rows; public function set_rows($rows){ $this->_rows=$rows; } public function output() { return ''.htmlspecialchars($this->_value) .' '; } } //下拉式選單也是繼承FormElement類別,並覆寫output方法,輸出select標籤動態表單 class FormElement_select extends FormElement { private $_itemarr= array(); public function set_itemgroup(Array $itemarr){ $this->_itemarr=$itemarr; } public function output() { $html=''; foreach($this->_itemarr as $key => $arr){ $select=($this->_value==$key)?'selected':''; $html.=''.$arr.''; } $html.=''; return $html; } } //單選框也是繼承FormElement類別,並覆寫output方法,輸出radio標籤動態表單 class FormElement_radio extends FormElement { private $_itemarr= array(); public function set_itemgroup(Array $itemarr){ $this->_itemarr=$itemarr; } public function output() { $html=""; foreach($this->_itemarr as $key => $arr){ $checked=($this->_value==$key)?'checked':''; $html.=''.$arr.''; } return $html; } } ?> ```