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

some work

parent bf08e333
No related branches found
No related tags found
No related merge requests found
......@@ -2,7 +2,7 @@
class BoolField extends Field
{
public function html() {
public function html($form) {
$html = '<div class = "form-group">
<label for = "form'.$this->name.'">'.ucfirst($this->name).'</label>
<input type = "checkbox" class="form-control" name = "'.$this->name.'" value ="'.$this->value.'">
......
......@@ -3,16 +3,24 @@
class Field {
protected $name;
protected $value;
public function __construct($name, &$value) {
protected $primary;
public function __construct($name, &$value, $primary=false) {
$this->name = $name;
$this->value =& $value;
$this->primary = $primary;
}
public function html() {
public function html($form) {
// Todo, if isset($_POST[$this->name]) && !$this->validate() => Show a error msg explanation for this line.
$disabled = "";
if($this->primary && $form->action == "Ajouter") { return ""; }
if($this->primary && $form->action == "Modifier") { $disabled = "disabled"; }
return '<div class="form-group">
<label for="form'.$this->name.'">'.ucfirst($this->name).'</label>
<input type="text" class="form-control" name="'.$this->name.'" value="'.$this->value.'" >
<input type="text" class="form-control" name="'.$this->name.'" value="'.$this->value.'" '.$disabled.'>
</div>';
}
......@@ -21,6 +29,11 @@ class Field {
and return false, if data is not valid !
*/
public function validate() {
// On ne peut pas changer la valeur de la clef primaire
if($this->primary && $this->value) {
return true;
}
$this->value = $_POST[$this->name];
return true;
}
......
......@@ -2,7 +2,7 @@
class Form {
protected $object;
protected $action;
public $action;
protected $error = null;
public function __construct(&$obj) {
......
......@@ -52,6 +52,7 @@ class Objet
$ret = array();
foreach(array_keys(get_object_vars($this)) as $keyName) {
if($keyName == "primaryAttr") { continue; }
if($keyName == $this->primaryAttr) { $ret[] = new Field($keyName, $this->$keyName, true); continue; }
$ret[] = new Field($keyName, $this->$keyName);
}
return $ret;
......
......@@ -18,7 +18,7 @@ switch($action) {
"keys" => array("nom", "proprio", "race", "poids", "genre", "sterile", "dateNaissance", "dateDeces", "taille", "code"));
include 'view/list.php';
break;
case "add":
case "addAnimal":
$animal = new Animal();
$formConf = $animal->getForm();
include 'view/form.php';
......
......@@ -7,7 +7,7 @@
<form role="form" method="post">
<input type="hidden" name="submitForm" value="1">
<?php foreach($formConf->getFields() as $field): ?>
<?php echo $field->html(); ?>
<?php echo $field->html($formConf); ?>
<?php endforeach; ?>
<button type="submit" class="btn btn-default"><?php echo $formConf->getSubmitText(); ?></button>
</form>
......
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