Skip to content
Snippets Groups Projects
Commit 4fa3c319 authored by clement's avatar clement
Browse files

Merge branch 'master' of gitlab.utc.fr:nf17-camp-p14/clivi

parents 30c31f40 7cad9691
No related branches found
No related tags found
No related merge requests found
...@@ -9,10 +9,20 @@ class Field { ...@@ -9,10 +9,20 @@ class Field {
} }
public function html() { public function html() {
// Todo, if isset($_POST[$this->name]) && !$this->validate() => Show a error msg explanation for this line.
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.'" > <input type="text" class="form-control" name="'.$this->name.'" value="'.$this->value.'" >
</div>'; </div>';
} }
/*
Load the data from $_POST
and return false, if data is not valid !
*/
public function validate() {
$this->value = $_POST[$this->name];
return true;
}
} }
\ No newline at end of file
...@@ -19,8 +19,19 @@ class Form { ...@@ -19,8 +19,19 @@ class Form {
if(isset($_POST["submitForm"])) { if(isset($_POST["submitForm"])) {
$post = true; $post = true;
// Apply validators // Apply validators
$success = true;
foreach($this->fields as $field) {
$success = $success && $field->validate();
}
// If all validators ok, commit // If all validators ok, commit
if($success) {
if($this->action == "Modifier") {
$this->object->update();
} else {
$this->object->insert();
}
}
} else { } else {
$post = false; $post = false;
} }
...@@ -38,4 +49,8 @@ class Form { ...@@ -38,4 +49,8 @@ class Form {
return $this->fields; return $this->fields;
} }
public function getAlerts() {
return '<p class="bg-danger">Code en cours d\'implémentation, l\'enregistrement n\'a pas été ajouté !</p>';
}
} }
\ No newline at end of file
...@@ -51,7 +51,7 @@ class Objet ...@@ -51,7 +51,7 @@ class Objet
return $ret; return $ret;
} }
public static function insertAll() public static function insert()
{ {
$className = get_called_class(); $className = get_called_class();
$dbName = lcfirst($className); $dbName = lcfirst($className);
......
#footer {
position: absolute;
bottom: 0;
width: 100%;
/* Set the fixed height of the footer here */
height: 30px;
background-color: #f5f5f5;
}
.footer_container {
width: auto;
max-width: 680px;
padding-top: 10px;
padding-bottom: 0px;
text-align : center;
}
.text-footer {
}
\ No newline at end of file
...@@ -3,6 +3,7 @@ ...@@ -3,6 +3,7 @@
<div class="page-header"> <div class="page-header">
<h1><?php echo $formConf->getTitle(); ?></h1> <h1><?php echo $formConf->getTitle(); ?></h1>
</div> </div>
<?php echo $formConf->getAlerts(); ?>
<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): ?>
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment