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