Skip to content
Snippets Groups Projects
Commit bdcca7ac authored by Matthieu Guffroy's avatar Matthieu Guffroy
Browse files

Avancement de la gestion du formulaire

parent ea6faf95
No related branches found
No related tags found
No related merge requests found
......@@ -2,18 +2,36 @@
class Form {
protected $object;
protected $action;
public function __construct(&$obj) {
$this->object =& $obj;
$this->fields = $this->object->getFields();
// TODO: Check if there is $_POST data (and if yes, insert or update the corresponding row)
// Update or Insert
if($this->object->{$this->object->primaryAttr}) {
$this->action = "Modifier";
} else {
$this->action = "Ajouter";
}
// Check posted values
if(isset($_POST["submitForm"])) {
$post = true;
// Apply validators
// If all validators ok, commit
} else {
$post = false;
}
}
public function getTitle() {
return "Ajouter un ".get_class($this->object);
return $this->action." un ".get_class($this->object);
}
public function getSubmitText() {
return "Ajouter";
return $this->action;
}
public function getFields() {
......
......@@ -2,6 +2,8 @@
class Objet
{
public $primaryAttr = "id";
public function fromDb($arr)
{
$att = get_object_vars($this);
......
......@@ -4,6 +4,7 @@
<h1><?php echo $formConf->getTitle(); ?></h1>
</div>
<form role="form" method="post">
<input type="hidden" name="submitForm" value="1">
<?php foreach($formConf->getFields() as $field): ?>
<?php echo $field->html(); ?>
<?php endforeach; ?>
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment