Czy teraz formularz nadal zawiera błędy?
Index.php - kontroler<?php
function __autoload($class){
require $class.'.php';
}
class index{
private $model; //
private $view;
private $val;
private $name;
private $form;
private $msg;
function __construct(){
$this->startModel();
$this->setData();
$this->getData();
$this->val();
$this->getData();
$this->startView();
}
private function startModel(){
$this->model = new form();
}
private function setData(){
if(isset($_POST['send'])){
$this->model->name = $_POST['name'];
}
}
private function getData(){
$this->name = $this->model->name;
$this->form = $this->model->st_form;
$this->msg = $this->val->msg;
}
private function val(){
if(isset($_POST['send'])){ $this->val = new val($this->name);
}
}
private function startView(){
$this->widok = new view($this->form,$this->msg);
}
}
new index();
?>
form.php - model<?php
class form
{
public $st_form;
public $name;
public function __construct()
{
$this->showForm();
}
//przpisywanie formularza do zmiennej
public function showForm()
{
$this->st_form = "<form action=\"index.php\" method=\"post\" >
<input type=\"hidden\" name=\"send\" >
<input type\"text\" name=\"name\" >
<input type=\"submit\" value=\"send\" >
</form>";
}
}
?>
view.php - widok<?php
class view{
private $form;
private $msg;
function __construct($form,$msg){
$this->form = $form;
$this->msg = $msg;
$this->render();
}
private function render(){
echo $this->form."<br/>"; }
}
?>
val.php - klasa odpowiedzialna za walidację<?php
class val{
private $name;
public $msg;
public function __construct($name){
$this->name = $name;
$this->check();
}
public function check(){
$this->msg = "pole nie jest puste";
} else{
$this->msg = "pole jest puste";
}
}
}
?>