Witam zaczynam programować w PHP Obiektowym zrobiłem sobie klasę Formularza znajduję się ona poniżej:
<?php
class Form
{
public $name;
public $method;
public $action;
public $value;
public $checked;
public $onclick;
public $text;
public $cols;
public $rows;
public function setOpenForm($name, $method, $action)
{
$this->name = $name;
$this->method = $method;
$this->action = $action;
}
public function setCheckboxForm($name, $value, $checked, $text)
{
$this->name = $name;
$this->value = $value;
$this->checked = $checked;
$this->text = $text;
}
public function setButtonForm($onclick, $value, $name)
{
$this->onclick = $onclick;
$this->value = $value;
$this->name = $name;
}
public function setPasswordForm($name)
{
$this->name = $name;
}
public function setTextForm($name)
{
$this->name = $name;
}
public function setRadioForm($name, $value, $checked, $text)
{
$this->name = $name;
$this->value = $value;
$this->checked = $checked;
$this->text = $text;
}
public function setTextareaForm($name, $cols, $rows, $text)
{
$this->name = $name;
$this->cols = $cols;
$this->rows = $rows;
$this->text = $text;
}
//Wyświetlanie wyników
public function getOpenForm()
{
return '<form name="'.$this->name.'" method="'.$this->method.'" action="'.$this->action.'">';
}
public function getCheckboxForm()
{
return '<label><input type="checkbox" name="'.$this->name.'" value="'.$this->value.'"/>'.$this->text.'</label>';
}
public function getButtonForm()
{
return '<input type="button" value="'.$this->value.'" class="button" style="width:60px;" onclick="'.$this->onclick.'">';
}
public function getPasswordForm()
{
return '<input type="password" value="'.$this->value.'" class="textbox" style="width:250px;" name="'.$this->name.'">';
}
public function getTextForm()
{
return '<input type="text" value="'.$this->value.'" class="textbox" style="width:250px;" name="'.$this->name.'">';
}
public function getRadioForm()
{
return '<label><input type="radio" name="'.$this->name.'" value="'.$this->value.'"/>'.$this->text.'</label>';
}
public function getTextareaForm()
{
return '<textarea class="textbox" style="width:250px;" name="'.$this->name.'">'.$this->text.'</textarea>';
}
}
?>
I tutaj pytanie do doświadczonych użytkowników czy to jest dobra klasa bo mi wydaję się że nie i jakie błędy popełniłem klasę wywołuję przez:
<?php
$form = new Form;
$form->setOpenForm('name', 'method', 'action');
$form->getOpenForm();
?>