Commit 2b57e0e9 authored by thejoelinux's avatar thejoelinux

validation sur membership_type

parent 30181ab9
......@@ -31,5 +31,23 @@ class Membership_Type extends Record {
$GLOBALS["data"]->select($sql, $membership_type, "Membership_Type");
return $membership_type;
}
public function validate_input(&$errors) {
$v = new Valitron\Validator($_REQUEST);
$v->rule('required', ['name', 'description', 'price']);
$v->labels(array(
'name' => 'Le nom',
'description' => 'La description',
'price' => 'Le prix'
));
if($v->validate()) {
$errors = null;
return true;
} else {
// Errors
$errors = $v->errors();
return false;
}
}
}
......@@ -53,6 +53,8 @@ class Record {
$sql = " UPDATE ".$this->table." SET ".$update_sql." updated_at = now()
WHERE id = ".$this->id;
return $GLOBALS["data"]->update($sql);
} else {
return true;
}
}
......
......@@ -48,7 +48,7 @@ class AppController {
}
public function set_message($msg, $level = "info") {
if(!is_array($GLOBALS["ihm_message"])) {
if(!array_key_exists("ihm_message", $GLOBALS) || !is_array($GLOBALS["ihm_message"])) {
$GLOBALS["ihm_message"] = array();
}
return array_push($GLOBALS["ihm_message"], array("level" => $level,
......@@ -159,6 +159,12 @@ class AppController {
echo json_encode($object);
exit();
}
} else {
if($this->format == "json") {
header($_SERVER['SERVER_PROTOCOL']." 422 Unprocessable entity", true, 422);
echo json_encode(array("msg" => "update failed"));
exit();
}
}
$objects = array();
$classname::fetch_all($objects);
......
{% extends 'modal.html' %}
{% extends 'modal_api.html' %}
{% block modal_title %}
{% if object.id %} Adhésion : {{ object.name }} {% else %} Nouveau type d'adhésion {% endif %}
{% endblock %}
{% block modal_body %}
<div class="alert alert-info alert-dismissible" role="alert" style="display: none" id="created_ok">
<button type="button" class="close" data-dismiss="alert" aria-label="Close"><span aria-hidden="true">&times;</span></button>
<span class="glyphicon glyphicon-ok"></span>
Création effectuée
</div>
<div class="form-group">
<label class="control-label col-sm-2" for="name">Nom</label>
<div class="col-sm-4">
<input type="text" id="name" name="name" class="form-control" value="{{ object.name }}"/>
<span id="help-name" class="help-block" style="display: none"></span>
</div>
<label class="control-label col-sm-2" for="price">Prix</label>
<div class="col-sm-4">
<input type="text" id="price" name="price" class="form-control" value="{{ object.price }}"/>
<span id="help-price" class="help-block" style="display: none"></span>
</div>
</div>
<div class="form-group">
<label class="control-label col-sm-2" for="description">Description</label>
<div class="col-sm-10">
<textarea id="description" name="description" class="form-control" rows="4">{{ object.description }}</textarea>
<span id="help-description" class="help-block" style="display: none"></span>
</div>
</div>
{% endblock %}
{% block javascript_fields %}
var fields = ['name', 'description', 'price'];
{% endblock %}
{% block javascript_msg %}
var msg = 'Voulez-vous réellement supprimer ce type d\'adhésion ?\n' +
'Cette action n\'est possible que si ce type n\'a été\n' +
......
......@@ -44,8 +44,8 @@ $('#save_button').click(function(){
$.post('api.php', post_data)
.done(function( data ) {
$('#created_ok').show();
//window.setTimeout(1000,
// location.href='index.php?o=' + $('#o').val() + '&a=list');
window.setTimeout(1000,
location.href='index.php?o=' + $('#o').val() + '&a=list');
})
.fail(function(data) {
$.each(data.responseJSON, function(key, val) {
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment