ну изначально расшифруйте ООП , класс => объект, ориентированно
в моей практике пока не приходилось писать гиганских классов , чтоб потом еще и клонировать или пускать потомков от него, можно и в пять классов на кодить подобную форму, вот с учебника не много поправил древний код
class htmlform {
public $actiontarget;
private $inputforms;
public $hiddenvariables;
public function __construct($action_target) {
$this->actiontarget = $action_target;
$this->inputforms = array();
$this->hiddenvariables = array();
}
public function rename(){
$form = '<form method="post" action="' . $this->actiontarget . '">' . PHP_EOL;
$form .= $this->inputformsstring();
$form .= $this->hiddenvariablesstring();
$form .= '<br/>' . PHP_EOL;
$form .= $this->submitbuttonstring();
$form .= '</form>';
return($form);
}
public function addinputform($input_form) {
if (!isset($input_form) || !is_object($input_form) || !is_subclass_of($input_form, 'htmlforminput')){
die(get_class($input_form));
} else {
array_push($this->inputforms, $input_form);
}
}
public function addinputbutton ($input_button) {
if (!isset($input_button) || !isobject($input_button) || !is_a($input_button, 'htmlinputbutton')){
die();
} else {
array_push($this->inputbuttons, $input_button);
}
}
public function addhiddenvariable($name, $value) {
if (!isset($value)) {
die();
} else {
$this->hiddenvariables[$name] = $value;
}
}
public function inputformsstring () {
$form = '';
$form_array = $this->inputforms;
foreach ($form_array as $input_form) {
$form .= '<b>' . $input_form->heading . '</b>';
if ($this->headingelementbreak()) {
$form .= '<br/>';
}
$form .= $input_form->rename() . '<br/>' . PHP_EOL;
}
return($form);
}
public function hiddenvariablesstring () {
$form = '';
while ($hidden_var = each($this->hiddenvariables)) {
$form .= '<input type="hidden" name="' . $hidden_var['key'] . '" "value="' . $hidden_var['value'] . '">' . PHP_EOL;
}
return($form);
}
public function headingelementbreak() {
return(true);
}
public function submitbuttonstring () {
$return_string = '<input type="submit" value="submit" />' . PHP_EOL;
return($return_string);
}
}
abstract class htmlforminput {
public $name;
public $heading;
function __construct() {
die();
}
function rename () {
die();
}
}
class htmlformselect extends htmlforminput
{
public $_valuearray = array();
public $_selectedvalue;
public function __construct ($name, $heading, $value_array, $selected_value=null) {
if (!isset($value_array)) {
die();
} elseif (!is_array($value_array)) {
die();
} else {
$this->name = $name;
$this->heading = $heading;
$this->_valuearray = $value_array;
$this->_selected_value = $selected_value;
}
}
public function rename() {
$form = '<select name="' . $this->name . '">';
while ($var_entry = each($this->_valuearray)) {
if ($submit_value == $this->_selected_value) {
$form .= '<option value="' . $var_entry['key'] . '" selected="selected">';
} else {
$form .= '<option value="' . $var_entry['key'] . '">';
}
$form .= $var_entry['value'];
}
$form .= '</select>';
return($form);
}
}
class htmlformtext extends htmlforminput {
public $initial_value;
public function __construct($name, $heading, $initial_value = '') {
if (!isset($name) || !isset($heading)) {
die();
}
$this->name = $name;
$this->heading = $heading;
$this->initial_value = $initial_value;
}
public function rename() {
return '<input type="text" name="' . $this->name . '" value="' . $this->initial_value . '" />';
}
}
class htmlformtextarea extends htmlforminput {
public $initial_value;
public $rows;
public $cols;
public function __construct($name, $heading, $initial_value= '', $rows=5, $cols=40)
{
if (!isset($name)) {
die();
}
$this->name = $name;
$this->heading = $heading;
$this->initial_value = $initial_value;
$this->rows = $rows;
$this->cols = $cols;
}
public function rename() {
$form = '<textarea "name="' . $this->name . '" rows="' . $this->rows . '" cols="' . $this->cols . '" ';
$form .= $this->additionalattributes();
$form .= '>';
$form .= $this->initial_value;
$form .= '</textarea>';
return $form;
}
public function additionalattributes() {
return('');
}
}сам вызов
$form = new HtmlForm('');
$form->addInputForm(new HtmlFormText('firstname', 'Имя'));
$form->addInputForm(new HtmlFormText('lastname', 'Фамилия'));
$form->addInputForm(new HtmlFormSelect('age', 'Возраст', array(0 => '10 - 19', 1 => '20 - 29', 2 => '30 - 39', 3 => 'Старикан'), 2));
$form->addInputForm(new HtmlFormTextArea('feedback', 'Текстареа', 'Произвольный текст', 5));
print($form->rename());половину новичек даже не в курит